How do I install from a local cache with pip?

pip install command
pip cache
pip install setuppy
python pip install --upgrade pip
pip config cache-dir
change pip cache location
pip install git
pip install from local directory

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-15

According to the Pip documentation:

Starting with v6.0, pip provides an on by default cache which functions similarly to that of a web browser. While the cache is on by default and is designed do the right thing by default you can disable the cache and always access PyPI by utilizing the --no-cache-dir option.

Therefore, the updated answer is to just use pip with its defaults if you want a download cache.

Original Answer

From the pip news, version 0.1.4:

Added support for an environmental variable $PIP_DOWNLOAD_CACHE which will cache package downloads, so future installations won’t require large downloads. Network access is still required, but just some downloads will be avoided when using this.

To take advantage of this, I've added the following to my ~/.bash_profile:

export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache

or, if you are on a Mac:

export PIP_DOWNLOAD_CACHE=$HOME/Library/Caches/pip-downloads
Notes
  1. If a newer version of a package is detected, it will be downloaded and added to the PIP_DOWNLOAD_CACHE directory. For instance, I now have quite a few Django packages.
  2. This doesn't remove the need for network access, as stated in the pip news, so it's not the answer for creating new virtualenvs on the airplane, but it's still great.

Install a package from your local pip download cache without , Install a package from your local pip download cache without touching the 'net. - pip-cache-install.py. While the cache is on by default and is designed do the right thing by default you can disable the cache and always access PyPI by utilizing the --no-cache-dir option. Therefore, the updated answer is to just use pip with its defaults if you want a download cache.

In my opinion, pip2pi is a much more elegant and reliable solution for this problem.

From the docs:

pip2pi builds a PyPI-compatible package repository from pip requirements

pip2pi allows you to create your own PyPI index by using two simple commands:

  1. To mirror a package and all of its requirements, use pip2tgz:

    $ cd /tmp/; mkdir package/
    $ pip2tgz packages/ httpie==0.2
    ...
    $ ls packages/
    Pygments-1.5.tar.gz
    httpie-0.2.0.tar.gz
    requests-0.14.0.tar.gz
    
  2. To build a package index from the previous directory:

    $ ls packages/
    bar-0.8.tar.gz
    baz-0.3.tar.gz
    foo-1.2.tar.gz
    $ dir2pi packages/
    $ find packages/
    /httpie-0.2.0.tar.gz
    /Pygments-1.5.tar.gz
    /requests-0.14.0.tar.gz
    /simple
    /simple/httpie
    /simple/httpie/httpie-0.2.0.tar.gz
    /simple/Pygments
    /simple/Pygments/Pygments-1.5.tar.gz
    /simple/requests
    /simple/requests/requests-0.14.0.tar.gz
    
  3. To install from the index you built in step 2., you can simply use:

    pip install --index-url=file:///tmp/packages/simple/ httpie==0.2
    

You can even mirror your own index to a remote host with pip2pi.

Python PIP local cache, [global] no-cache-dir = false download-cache=/usr/local/pip/cache. Next create the folder. mkdir -p /usr/local/pip/cache. Then give it write access. chmod -R 755 /usr/local/pip/cache. You can instead use your profile config file ~/.bash_profile. So open ~/. export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache. That is The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache .If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy instead of retrieving it from the remote register . Enabling the local cache of pip

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 ~/.pip/pip.conf, and add the following contents:

[global]
download_cache = ~/.cache/pip

On OS X, a better path to choose would be ~/Library/Caches/pip since it follows the convention other OS X programs use.

Using a local cache for pip packages – dominicrodger.com, alias pipcache= 'pip install --download ${HOME}/.pip-packages' the packages to my local cache, the second installs them from the cache. How do I install from a local cache with pip? 9 answers How do you prevent PIP from re-downloading previously downloaded packages? I'm testing the install of matplotlib, an 11MB package that depends on several distro-specific packages.

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:

pip install --no-install --use-mirrors -I --download=$SDIST_CACHE <package name>

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:

pip install --find-links=file://$SDIST_CACHE --no-index --index-url=file:///dev/null <package name> 

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.

pip install, Caching. Wheel Cache. Hash-Checking Mode. Hashes from PyPI. Local python setup.py egg_info works without their build dependencies being installed. Create a configuration file named ~/.pip/pip.conf, and add the following contents: [global] download_cache = ~/.cache/pip 2) Install a package #pip install six * Add the package "six" to cache and

Package index mirrors and caches, Mirroring or caching of PyPI can be used to speed up local package installation, allow offline work, handle corporate firewalls or just plain  pip install psycopg2 Instead of: pip install psycopg2==2.4.1 That installs 2.4.4 instead of the earlier version. Now even after I pip uninstall psycopg2 and attempt to reinstall with the correct version, it appears that pip is re-using the cache it downloaded the first time.

pip-cache · PyPI, Local PyPi Package Name Cache. pip install pip-cache. Copy PIP The cache is stored in $XDG_DATA_HOME/pip-cache/all-packages.txt , where  pip install --help -e, --editable <path/url> Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url. eg, pip install -e /srv/pkg. where /srv/pkg is the top-level directory where 'setup.py' can be found.

Python pip install from local cache, Python pip install from local cache http://fosshelp.blogspot.com/2014/11/python-​pip-install Duration: 8:13 Posted: Dec 3, 2014 There are three main ways to clear cache in a Windows 10 computer: temporary files cache, File Explorer history, and browser cache. Menu icon A vertical stack of three evenly spaced horizontal lines.

What is pip's `--no-cache-dir`, (36)user@localhost:~/workspace/django-nginx/36$ pip install django -- for speeding up installation by using local cached copies of packages:. According to pip's caching documentation from version 6 you can use the --no-cache-dir option. But that didn't help me as I was using a wrapper (pinax starter projects) that runs pip in the background to install several packages.

Comments
  • Note that as of pip 6.0 (2014-12-22), pip will cache by default. See pip.pypa.io/en/stable/reference/pip_install.html#caching for details.
  • It doesn't just reduce download bandwidth time, it also can eliminate the time spent crawling the PyPI index to check available versions of packages, and if you are caching wheels, it can eliminate time spent building wheels for packages that don't provide them. It adds up to a very substantial speed boost.
  • Maybe better idea is to put it into .bashrc, because bash_profile is executed only during login. That's up to you, and anyway it's a good advice :)
  • On macs it is loaded at the beginning of any shell.
  • PIP_DOWNLOAD_CACHE is seriously flawed and I wouldn't recommend using it for things like getting packages out to your deployment machines. It also still relies on pypi.python.org being reachable. Great for a local development cache, but not suitable for heavier uses.
  • @slacy Could you comment on why it is seriously flawed? If you don't want PyPI to be reachable, that's what --no-index is for; a download cache is surely orthogonal to reaching PyPI or not!
  • @lvh slacy's answer below explains why Pip's download cache is flawed. I've also seen pip install taking longer with cache enabled, bizarrely. pip-accel and basket appear to be better options.
  • +1 pip2pip works great!! I don't like relying on network connectivity that much. It fails when you most need it.
  • this works great, it answers my question stackoverflow.com/questions/18052217/… , can yon answer there as well ?
  • Maybe it was implied, but it's worth mentioning explicitly: pip2tgz detects if you have already downloaded the package to the designated directory, so if you run the same install line or several install lines that have overlapping dependencies, it will only download each package once.
  • And If I wanted to store them globally for other users of the same PC to access? How would I do that? I figure the config file would have to be placed in /etc or something.