如何安装具有自定义依赖项的自定义python包? [英] How to install my custom python package with its custom dependencies?
问题描述
我想找到一种方法来安装自己的python软件包,该软件包依赖于其他自定义python软件包.
I would like to find a way to install my own python package which depends on other custom python packages.
我按照本指南创建了自己的python软件包:>://://python-packaging .readthedocs.iao/zh/latest/
I followed this guide to create my own python packages: https://python-packaging.readthedocs.iao/en/latest/
对于所有软件包,最小结构为:
For all packages, the minimal structure is:
myOwnPackage/
myOwnPackage/
__init__.py
setup.py
现在,我创建了一个依赖于其他自定义程序包的程序包.其结构为:
Now, I created a package wich depends on other custom packages. Its structure is:
myOwnPackage/
dependencies/
packageA
packageB
myOwnPackage/
__init__.py
setup.py
我的问题是:如何使用pip轻松安装myOwnPackage
及其自定义依赖项?
My question is: How to easily install myOwnPackage
and its custom dependencies with pip ?
对于上面的示例,当我像这样调用pip时,我想安装myOwnPackage,packageA和packageB:pip install myOwnPackage
For the above example, I would like to install myOwnPackage, packageA and packageB when I call pip like that: pip install myOwnPackage
我没有找到在setup.py中包含依赖项名称的方法,就像我可以对numpy
,pyqt5等官方python软件包所做的那样.
I did not find a way to include dependency names in setup.py like I can do for offcial python packages like numpy
, pyqt5 etc.
我找到了一种方法,通过在pip中使用requirements.txt来部分解决我的问题:
I find a way to solve my problem partially by using a requirements.txt with pip:
pip install -r requirements.txt myOwnPackage
这是我编写需求文件的方式:
and here is how I wrote the requirement file:
./dependencies/packageA
./dependencies/packageB
我工作得很好,但是当我有这样的递归依赖项时:
I works well, but not when I have recursive dependencies like that:
myOwnPackage/
dependencies/
packageA/
dependencies/
packageC
packageA/
__init__.py
setup.py
requirements.txt
packageB
myOwnPackage/
__init__.py
setup.py
requirements.txt
具有最高要求的pip.txt将安装myOwnPackage,packageA和packageB,但它不知道必须安装是packageA依赖项的packageC.
pip with the top-level requirements.txt will install myOwnPackage, packageA and packageB but it does not know that it has to install packageC which is a packageA dependency.
有什么主意吗?
推荐答案
我几乎解决了我的问题.
I almost solved my problem.
我需要使用以下命令构建每个依赖项:python setup.py sdist
为了创建单个程序包文件(tar.gz)
I need to build each dependency with the following command: python setup.py sdist
in order to create a single package file (tar.gz)
然后,我可以在顶级程序包setup.py中调用它们:
Then, I can call them in the top-package setup.py:
...
dependency_links=["file:/local/path/myOwnPackage/dependencies/packageA/dist/packageA-0.1.tar.gz"],
install_requires=["packageA"],
...
最后,我运行以下命令来安装myOwnPackage
及其本地依赖项:
Finaly, I run the following command to install myOwnPackage
and its local dependencies:
pip install . --process-dependency-links
如果按照上述方法正确构建和设置了所有存储库,则它将安装所有递归依赖项.
It installs all recursive dependencies if all repo are built and set correctly as describe above.
--process-dependency-links
在上一个版本的pip中已被删除...
--process-dependency-links
has been removed in last version of pip...
这篇关于如何安装具有自定义依赖项的自定义python包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!