Skip to content

Instantly share code, notes, and snippets.

@tomviner
Last active December 15, 2015 19:19
Show Gist options
  • Save tomviner/5310817 to your computer and use it in GitHub Desktop.
Save tomviner/5310817 to your computer and use it in GitHub Desktop.
Offline package installation, and download script to pre-run. Include package_sources in your repo!

Offline installs

This started with Jonathan Hartley's input to the "pypi's going slowly twiscusion" he suggested:

To download sdists into dirname "pip install -d dirname -r reqs.txt"

Then to install "pip install -r reqs.txt --no-index --find-links=file://dirname". This bit works even w/ no network...

So I've downloaded the packages with --download and made this install script:

$ cat install_packages.sh
pip install --no-index --find-links=file://requirements/package_sources -r requirements.txt

Usage:

# defaults to requirements.txt
./install_packages.sh

# or
./install_packages.sh -r ./requirements/dev.txt
# or
./install_packages.sh South

When a new package is needed:

Install as usual, then run:

./requirements/download_package_cache.sh
# won't work if run from within requirements directory

You should see a new package in requirements/package_sources/ which you can then commit after adding a new line to requirements/base.txt (or other req file).

#!/bin/bash
REQ_ARG="$@"
REQ_DEF="$(pip freeze | xargs)"
# "i" is for ignoring packages already downloaded
yes i | pip install --use-mirrors --download requirements/package_sources/ ${REQ_ARG:=$REQ_DEF}
#!/bin/bash
REQ_ARG="$@"
REQ_DEF="-r requirements.txt"
pip install --no-index --find-links=file://$(readlink -f requirements/package_sources/) ${REQ_ARG:=$REQ_DEF}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment