How to install my custom python package with its c

2019-08-30 09:29发布

问题:

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 ?

回答1:

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