Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching remote repository for pip installs

In my pi requirements file, I require specific commits of various repos, ie:

git+http://github.com/frankban/django-endless-pagination.git@725bde91db#egg=django-endless-pagination

The problem I'm having with this is that it apparently requires pip to clone the repo anew for every install, ignoring the default download cache entirely.

Are there any ways to require this repo to be cached locally? Or, alternately, what is the best solution to package this up and keep the package locally available?

like image 501
Martin Avatar asked Jan 26 '15 20:01

Martin


People also ask

Does pip cache?

Pip uses a caching mechanism that allows you to download and install Python packages faster. It works by storing a cache of the downloaded packages on the local wheel. The caching mechanism allows pip to improve the download and installation of the packages.

Is it safe to delete cache pip directory?

It is safe to delete the user cache directory. It will simply cause pip to re-download all packages from PyPI.


1 Answers

You can do two things: use an editable install, or cache the result of the install as a wheel.

Using the -e switch causes pip to clone the repository into the src subdirectory of your virtualenv; you can then reuse that copy each time you want to re-install:

pip install -e -r requirements.txt

Pip then just re-uses the existing source each time you re-run the command (updating from git rather than pulling in a completely new copy of the repo), or, since the installation uses the actual working directory, you can just use git pull in src/django-endless-pagination instead.

You can cache the result of the pip install as a Python Wheel:

pip wheel --wheel-dir=/tmp/wheelhouse -r requirements.txt

This installs all the requirements and creates wheels for each in /tmp/wheelhouse. You can then re-use the wheelhouse for subsequent installs:

pip install --use-wheel --no-index --find-links=/tmp/wheelhouse -r requirements.txt

The wheels won't be updated from the repository however.

like image 125
Martijn Pieters Avatar answered Sep 27 '22 20:09

Martijn Pieters