Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a standalone pip package (all deps included)

Tags:

python

pip

What's the best way to create a standalone pip package, that would run on any machine with bare package installed?

Say, I want to package pelican so that it'll run at all computers with python installed (assume for a moment that all dependencies are pure python).

like image 277
HBase Avatar asked Nov 29 '25 22:11

HBase


1 Answers

There are two solutions in my mind: bundles and pip install --no-install trick.

Using bundles:

$ virtualenv venv
$ venv/bin/pip install pelican
$ venv/bin/pip freeze > all-packages.txt
$ venv/bin/pip bundle allpackages.pybundle -r all-packages.txt

(I created venv to have a clean environment and all-packages.txt contain only what pelican needs)

And you just need to distribute allpackages.pybundle, and who wants those packages that must do:

$ venv/bin/pip install allpackages.pybundle -r all-packages.txt

Using pip install --no-install:

pip can download all packages to a directory, and you can distribute those packages. Assuming you have all-packages.txt containing all the packages you need to distribute, you can use the --no-install with --download-dir options:

$ mkdir tarballs
$ venv/bin/pip install --no-install --download-dir=tarballs -r all-packages.txt

If you use the last trick and wants to install those packages using pip:

$ venv/bin/pip install --no-deps --no-index tarballs/*

The option no-deps is needed because pip looks for dependencies before installing the wnated package. I used --no-index just to show you pip does not needs to go to PyPI to find anything, and you don't even need internet connection in that step.

like image 77
Hugo Tavares Avatar answered Dec 01 '25 11:12

Hugo Tavares