How to install my custom Python package with its custom dependencies?

2024/10/10 20:19:16

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__.pysetup.py

Now, I created a package which depends on other custom packages. Its structure is:

myOwnPackage/dependencies/packageApackageBmyOwnPackage/__init__.pysetup.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 official 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/packageCpackageA/__init__.pysetup.pyrequirements.txtpackageBmyOwnPackage/__init__.pysetup.pyrequirements.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?

Answer

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

https://en.xdnf.cn/q/69854.html

Related Q&A

How to call a function only Once in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.The com…

Generating Compound Pie, or Pie of Pie Charts

Below is an example of a compound pie chart, also known as a pie of pie chart drawn using Excel. Is it possible to create a figure like this using python?

GitPython : git push - set upstream

Im using GitPython to clone a master branch and do a checkout of a feature branch, I do my local updates, commit and push back to git. The code snippet looks like below, Note : my branch name is featur…

How to access multi-level index in pandas data frame?

I would like to call those row with same index.so this is the example data frame, arrays = [np.array([bar, bar, baz, baz, foo, foo, qux, qux]), np.array([one, two, one, two, one, two, one, two])]df = p…

How to represent graphs with IPython

Recently I discovered IPython notebook which is a powerful tool. As an IT student, I was looking for a way to represent graphs in Python. For example, I would like to know if theres a library (like num…

How to check TypeVars Type at runtime

I have a generic class Graph[Generic[T], object]. My question, is there any function which returns type passed as generic to the class Graph>>> g = Graph[int]() >>> magic_func(g) <…

Can django-pagination do multiple paginations per page?

If it cant then are there any other alternatives (either Djangos native pagination or an alternate package) that allows multiple paginations per page?I would like to display a list of about 5 objects …

List directory file contents in a Django template

Im just learning Python & Django. (Thanks to everyone who contributes here -- its been an invaluable resource!)One seemingly basic thing that Im having trouble with is rendering a simple list of s…

Produce PDF files, draw polygons with rounded corners

Whats the right tool for the job if I want to write a Python script that produces vector graphics in PDF format? In particular, I need to draw filled polygons with rounded corners (i.e., plane figures…

How can I unit test this Flask app?

I have a Flask app that is using Flask-Restless to serve an API.I have just written some authentication that checksIf the consumers host is recognised The request includes a hash (calculated by encrypt…