Skip to content

Instantly share code, notes, and snippets.

@prateek
Last active March 23, 2024 17:58
Show Gist options
  • Save prateek/525d14823c3df3ee9472 to your computer and use it in GitHub Desktop.
Save prateek/525d14823c3df3ee9472 to your computer and use it in GitHub Desktop.

Offline Python Package Install Notes

Two common cases which make the install of Python packages harder due to networking issues are: a) Install behind a Proxy b) Install without access to the internet

(a) Install behind a Proxy

In the case where the target machine connects to the internet over a network proxy, export the following environment vars, as appropriate - http_proxy and https_proxy. Eg:

$ export https_proxy=http://proxy.mydomain.com:<port>
$ export http_proxy=http://proxy.mydomain.com:<port>
$ pip install <package>

(b) Install without access to the internet

In the case where the target machine does not have connectivity to the internet, you have to download the package and dependencies using a machine which does have connectivity to the internet. After which the install can follow. Sample instructions -

Step 1. Download Packages for Offline Install

Execute the instructions below download the packages on a machine which is able to connect to the internet.

# if a single package is being installed
$ pip install <package> --download /tmp/offline_packages

# or, if a list of dependencies are to be installed
$ pip install --download /tmp/offline_packages -r requirements.txt

Step 2. Transfer downloaded packages

Transfer downloaded packages to the target machine where the install is to be performed. Use scp/sftp/etc.

Step 3. Install packages

Assuming the directory /tmp/transferred_packages contains the contents of /tmp/offline_packages from the earlier machine, execute the following steps on the the target machine.

# if a single package is being installed
$ pip install --no-index --find-links="/tmp/tranferred_packages" <package>

# if a list of dependencies are to be installed
$ pip install --no-index --find-links="/tmp/tranferred_packages" -r requirements.txt

References

@tucked
Copy link

tucked commented Oct 1, 2019


Usage:
  pip install [options] <requirement specifier> [package-index-options] ...
  pip install [options] -r <requirements file> [package-index-options] ...
  pip install [options] [-e] <vcs project url> ...
  pip install [options] [-e] <local project path> ...
  pip install [options] <archive url/path> ...

no such option: --download

Step 1 should probably be

pip wheel --wheel-dir /tmp/offline_packages <package>

or

pip wheel --wheel-dir /tmp/offline_packages -r requirements.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment