I install a lot of the same packages in different virtualenv environments. Is there a way that I can download a package once and then have pip install from a local cache?
This would reduce download bandwidth and time.
I install a lot of the same packages in different virtualenv environments. Is there a way that I can download a package once and then have pip install from a local cache? This would reduce download bandwidth and time. |
|||||
|
Updated Answer 19-Nov-15According to the Pip documentation:
Therefore, the updated answer is to just use pip with its defaults if you want a download cache. Original AnswerFrom the pip news, version 0.1.4:
To take advantage of this, I've added the following to my
or, if you are on a Mac:
Notes
|
|||||||||||||||||||||
|
In my opinion, From the docs:
You can even mirror your own index to a remote host with |
|||||||||||||||||
|
PIP_DOWNLOAD_CACHE has some serious problems. Most importantly, it encodes the hostname of the download into the cache, so using mirrors becomes impossible. The better way to manage a cache of pip downloads is to separate the "download the package" step from the "install the package" step. The downloaded files are commonly referred to as "sdist files" (source distributions) and I'm going to store them in a directory $SDIST_CACHE. The two steps end up being:
Which will download the package and place it in the directory pointed to by $SDIST_CACHE. It will not install the package. And then you run:
To install the package into your virtual environment. Ideally, $SDIST_CACHE would be committed under your source control. When deploying to production, you would run only the second pip command to install the packages without downloading them. |
|||||||||||||||||||||
|
For newer Pip versions:Newer Pip versions now cache downloads by default. See this documentation: https://pip.pypa.io/en/stable/reference/pip_install/#caching For older Pip versions:Create a configuration file named
On OS X, a better path to choose would be |
|||||||||||||
|
Starting in version 6.0,
More information from the above link:
|
||||
|
pip wheel is an excellent option that does what you want with the extra feature of pre-compiling the packages. From the official docs:
Now your
Note that not all the the packages will be completely portable across machines. Some packages will be built specifically for the Python version, OS distribution and/or hardware architecture that you're using. That will be specified in the file name, like |
||||
|
Using pip only (my version is 1.2.1), you can also build up a local repository like this:
In the first call of pip, the packages from the requirements file are looked up in the local repository (only), and then installed from there. If that fails, pip retrieves the packages from its usual location (e.g. PyPI) and downloads it to the ( |
||||
|
A simpler option is Given a package name, it will download it and all dependencies to a central location; without any of the drawbacks of pip cache. This is great for offline use. You can then use this directory as a source for
Or
You can also use it to update the basket whenever you are online. |
|||
|
There is a new solution to this called pip-accel, a drop-in replacement for
We've seen around 10x speedup from switching from |
|||
|