[英]How to create a shareable python distribution package that can be installed using pip?
I want to share my python code with my colleague in a way that he will get the distribution package and using pip the package can be installed on his/her machine.我想与我的同事分享我的 python 代码,他将获得分发包并使用 pip 将包安装在他/她的机器上。
I created .whl file which i thought can be directly installed through the pip install command.我创建了 .whl 文件,我认为可以通过 pip install 命令直接安装它。 Though it was installed successfully, when i start using it shows the error.虽然它安装成功,但当我开始使用它时显示错误。
Is this possible like i give .whl file and it can be used in other's machine once installed through pip install command ?这可能就像我提供 .whl 文件一样,一旦通过 pip install 命令安装,它就可以在其他机器上使用吗?
I'm trying to do it on windows machine.我正在尝试在 Windows 机器上执行此操作。
Here is the setup.py :这是 setup.py :
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name='dokr',
version='0.1',
scripts=['dokr'] ,
author="Debapritam Chakra",
author_email="debapritam22@gmail.com",
description="A Sample package",
long_description=long_description,
long_description_content_type="text/markdown",
url="",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 2.7",
"",
"Operating System :: OS Independent",
],
)
package that i am trying to create is dokr and have file named dokr in the same directory which has the content shown below.我试图创建的包是 dokr 并且在同一目录中有名为 dokr 的文件,其内容如下所示。
#!/usr/bin/env python
echo "hey there, this is a pip package"
used the command python setup.py sdist bdist_wheel to generate the distribution package.使用命令python setup.py sdist bdist_wheel生成分发包。
To install package on my machine, I used the command :要在我的机器上安装软件包,我使用了命令:
python -m pip install dist/name-of-wheel-file.whl python -m pip install dist/name-of-wheel-file.whl
It showed it is installed successfully(even checked using the pip list ).它表明它已成功安装(甚至使用pip list检查)。 It throws the error when i try to import the package as当我尝试将包导入为时,它会引发错误
import dokr进口医生
Traceback (most recent call last):回溯(最近一次调用最后一次):
File "", line 1, in文件“”,第 1 行,在
ImportError: No module named dokr导入错误:没有名为 dokr 的模块
Additional observation : Python on my machine is installed under C:\\Python27.附加观察:我机器上的 Python 安装在 C:\\Python27 下。 After installing the package from whl file using pip, I could see there is a directory created under the path : C:\\Python27\\Lib\\site-packages\\ named dokr-0.1.dist-info .For which pip list shows that the module is present.使用 pip 从 whl 文件安装包后,我可以看到在路径下创建了一个目录: C:\\Python27\\Lib\\site-packages\\ 名为dokr-0.1.dist-info .For which pip list 显示该模块存在。
But there is no such folder having the python file dokr itself, which i want to import in other python file.但是没有这样的文件夹具有 python 文件 dokr 本身,我想在其他 python 文件中导入它。 which shows error during importing.在导入过程中显示错误。
I am new to python and this platform as well.我也是 python 和这个平台的新手。 Any lead would be helpful.任何线索都会有所帮助。
Ofcourse, you can create a python distribution package.当然,你可以创建一个python分发包。
Can you clearly show what is the error?你能清楚地表明错误是什么吗? However, you can look into the following link!但是,您可以查看以下链接! : Packaging Python Projects :打包 Python 项目
Hope this helps!希望这可以帮助!
Fortunately found the cause of the problem.幸运的是找到了问题的原因。
I did not pass the argument( packages which takes the list of packages to be included ) in the setup function, for which packages could not be copied.我没有在 setup 函数中传递参数(包含要包含的包列表的包),无法复制包。
Following article and an awesome answer helped to sort out the issue.以下文章和一个很棒的答案有助于解决问题。
https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide
pip install . 点安装。 creates only the dist-info not the package 只创建 dist-info 而不是包
And I thank everyone who came here to help.我感谢所有来到这里提供帮助的人。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.