0

I was wondering how to make a .tar.gz file of all pip packages used in a project. The project will not have access to the internet when a user sets up the application. So, I though it would be easiest to create .tar.gz file that would contain an all the necessary packages and the user would just extract and install them with a setup.py file (example) or something along those lines. Thanks

  • I think [pip2pi](https://github.com/wolever/pip2pi) will serve your purposes pretty well. It has an associated tool pip2tgz that sounds like what you need. – ajoseps Aug 22 '17 at 16:07
  • 2
    Possible duplicate of [What's the standard way to package a python project with dependencies?](https://stackoverflow.com/questions/38243682/whats-the-standard-way-to-package-a-python-project-with-dependencies) – Joao Vitorino Aug 22 '17 at 16:10
  • Hey, Thanks @ajoseps That worked out great! – Stephen Rawson Aug 22 '17 at 16:22

2 Answers2

2

Do:

  1. pip freeze > requirements.txt It will store all your requirements in file requirements.txt

  2. pip wheel -r requirements.txt --wheel-dir="packages" It will pre-package or bundle your dependencies into the directory packages

  3. Now you can turn-off your Wi-fi and install the dependencies when ever you want from the "packages" folder. Just Run this:

pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps packages/*

Thanks :)

0

I also had a similar use case and I achieved it using pip wheel. Using pip wheel, you can bundle up all of a project's dependencies, with any compilation done, into a single archive.

I found it a more easy and appropriate approach for my use case than the one mentioned above by @ajoseps.

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

You can then install from the archive like this:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps ${tempdir}/*

Sources: https://pip.pypa.io/en/stable/user_guide/#installation-bundles

Arslan Qadeer
  • 1,969
  • 1
  • 9
  • 5