How do I install a pip package on a machine without Internet access?

I’m working on a Linux machine without (direct) Internet access. I want to pip install foo for some pypi package foo, but – obviously, that won’t work. I have, of course, other machines which are connected the Internet.

How would I go about determining what files need to be downloaded, downloading them and installing them once they’re on the isolated machine?

Notes:

  • I’d rather get a Python-version-independent answer, but if it is version-dependent, let’s assume Python 3.6 or later.
  • This question sounds the same, but it’s actually about installing pip istelf.
Asked By: einpoklum

||

You can ask pip to download a .whl wheel file (and its dependency wheel files) instead of installing it:

pip download foo

(on an Internet-connected system, replacing foo with your actual package as appropriate).

Then copy the downloaded files to the off-line system, and install with

pip install --no-index --find-links . foo

You can replace . with the path to the directory with the wheel(s), and foo with the package name.

In both cases, foo can be replaced with -r /path/to/requirements.txt. pip download supports a variety of options to specify the version of Python to download for, the architecture etc.

Answered By: Stephen Kitt