python怎么自定义安装_如何安装具有自定义依赖项的自定义python包?

I would like to find a way to install my own python package which depends on other custom python packages.

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

My question is: How to easily install myOwnPackage and its custom dependencies with pip ?

For the above example, I would like to install myOwnPackage, packageA and packageB when I call pip like that: pip install myOwnPackage

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.

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 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.

Any idea ?

解决方案

I almost solved my problem.

I need to build each dependency with the following command: python setup.py sdist in order to create a single package file (tar.gz)

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"],

...

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 has been removed in last version of pip...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值