Packing a single Python module with dependencies

I have one Python3 .py module with several dependencies (lockfile, python-daemon). Is there an easy way to package this with its “dependencies” so that users do not need to download and install other modules? All the included installations are what I'm trying to do.

I tried looking at setuptools, distributing and distutils, and ended up being even more confusing than when I started.

+4
source share
5 answers

The easiest way that I often use is to put all your dependencies in a single file (usually called requirements.txt ), and then you ask the user to run the following command:

 pip install -r requirements.txt 

And here is an example of the contents of the file ( https://github.com/cenkalti/pypi-notifier/blob/master/requirements.txt ):

 Flask==0.10.1 Flask-Cache==0.12 Flask-SQLAlchemy==1.0 Flask-Script==0.5.3 GitHub-Flask==0.3.4 Jinja2==2.7 MarkupSafe==0.18 SQLAlchemy==0.8.2 ... 
+1
source

cx_Freeze should do what you are looking for.

+1
source

You could easily do this with something as simple as a .zip file containing all the files; while all files are exported to the same directory, then all of them should work! A crash occurs if there are many dependencies for modules, that is, they have additional folders that you need to find.

I also think that many people / companies write their own packaging systems so that all modules are in the 1.py file, which opens in the console and exports everything to the right place. This will require a significant amount of work, although you may try to find one ready. I followed this method, and he did not become too taxed. I had to unzip the zip files with the files in ...

As another solution, you can try PyExe (I think so) to export everything to a single .exe file (Windows only)

I personally havn't used setuptools, distribute or distutils, so I can not comment on them, unfortunately.

1 Another thing to keep in mind is the licenses for each module, some of which cannot be redistributed, so check first!

0
source

py2exe is fine, but it will limit you to Windows.

The best way to do this without restricting the audience and following generally accepted recommendations is to create the requirements.txt and setup.py and then upload the project to github . See https://github.com/sourcegraph/python-deps as a reference. requirements.txt lists the dependencies in a simple, easy-to-read format, and you specify the library commands and modules that your project installs using the scripts and py_modules in the setup.py file.

Assuming your git repository is located at github.com/foo/bar, your users can do pip install git+https://github.com/foo/bar .

0
source

Read the official Python packaging tutorial .

  • You create a Python package from your module using setup.py

  • In setup.py you can declare which other Python packages should be installed as dependencies

  • Alternatively, you can narrow down the application dependency version using requirements.txt .

0
source

Source: https://habr.com/ru/post/1501707/


All Articles