简体   繁体   English

如何创建可使用 pip 安装的可共享 python 分发包?

[英]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.

相关问题 如何在 Python 中创建可以与 PIP 一起安装的 CLI? - How to create a CLI in Python that can be installed with PIP? 如何创建仅由 pip 安装的 python package 列表 - how to create python package list installed by pip only 如何卸载在anaconda中使用pip安装的opencv-python包? - how to uninstall opencv-python package installed by using pip in anaconda? 安装了 python package 与 pip 但不能导入说 ZEFE90A8E604A7C640E88D03A78D6 - Installed python package with pip but can't import said package 如何使用 pip 和 PyPI 安装 Python 模块单个文件? - How can a Python module single file be installed using pip and PyPI? 我已经在pip中上传了一个Python包,然后pip安装了这个包,但是我在Python Interpreter中无法导入这个包 - I have uploaded a Python package in pip, then pip installed this package, but I can't import this package in Python Interpreter 引用用pip安装的python包 - Referencing a python package installed with pip 如何为pip安装的python包启用shell命令行参数? - How can one enable a shell command line argument for a python package installed for pip? 当我的计算机上有 Python 2、Python 3 和 Anaconda 时,如何控制将包安装到哪个 Python 发行版? - How can I control which Python distribution to pip install a package to when I have Python 2, Python 3, and Anaconda on my computer? 如何导入安装package的pip? - How to import pip installed package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM