9

I have a pip requirements file with pinned package versions. I need to install PyPI packages on a system without a direct internet connection. How can I easily download the packages I need now, for pip installation later, without visiting each package page myself?

lofidevops
  • 15,528
  • 14
  • 79
  • 119
  • possible duplicate of [How to use Python's pip to download and keep the zipped files for a package?](http://stackoverflow.com/questions/7300321/how-to-use-pythons-pip-to-download-and-keep-the-zipped-files-for-a-package) – Jayanth Koushik Mar 20 '14 at 11:30

2 Answers2

9

The pip documentation has a good example of fast and local installs:

$ pip install --download <DIR> -r requirements.txt
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt

This is mostly for speed, but if you do the first step on an internet connected machine, copy the files to the other machine, then run the second step, you should be able to install all of your requirements without an internet connection.

ford
  • 10,687
  • 3
  • 47
  • 54
  • Although the OP's question didn't ask for cross-platform functionality, it should be warned that this solution does not solve cross-platform issues (i.e., you can't simply run the first command on a windows machine, and then run the second on a linux machine as some of the downloaded packages will be platform specific). – Eduardo Aug 13 '15 at 18:46
  • 2
    The --download option has been deprecated for pip (will be removed in version 10) and replaced with its own command. The equivalent command is "pip download -r -d " – musingsole Jun 19 '17 at 16:20
2

To add to ford's answer, in order to get around cross-platform issues one can do the following instead:

On the machine with internet access do:

$ pip install --download <DIR> -r requirements.txt
$ pip install --download <DIR> -r requirements.txt --no-use-wheel

This will download available wheels for the packages in case the wheel is cross platform, but will also download the source so the packages can be built on any platform in case the wheel doesn't work for the target system.

Then, as ford has suggested, after moving the from the machine with internet access to the other machine do:

$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt

I can't guarantee this will work in every case, but it worked for me when trying to download a package and its dependencies on a Windows machine with internet access to install on a CentOS machine without internet access. There may also be other factors to consider if using different versions of Python on each machine (in my case I had Python 3.4 on both).

Eduardo
  • 436
  • 1
  • 5
  • 12