How to setup a local pypi mirror
Feb 4, 2016 · Commentscode pippython
It is quite easy to set up a local pypi server.
Some details can be found here. You can also use devpi if you prefer but it seems overly complicated for a job that is easily achieved by pip.
Let’s look at how to use pip
for local installation.
Firstly, it is possible to install all requirements beforehand in a separate directory.
We can use the following commands:
pip install --download DIR -r requirements.txt
If you prefer wheel, then use the following:
pip wheel --wheel-dir DIR -r requirements.txt
Now, when we want to install from this given directory DIR
, then
the following command can help:
pip install --no-index --find-links=DIR -r requirements.txt
If you are using these in a current setup and you feel it still slows you down then the reason would be
one of the first few commands where the request is still going to the internet.
If you want to speed up the whole process then perhaps you need to send out a request to the internet
only if a new package is available in the requirements.txt file otherwise you can skip that part altogether,
just leading onto pip install --no-index
This will make your installation a flash.
One quick and dirty way to maintain a local copy of requirements.txt file and figure out on every commit of code change in the project, whether a new requirement has been added to that list. In that case, install it + update your local copy.
Here’s a sample code to put all changes in a single line that you can feed into pip install
sdiff -s /tmp/1 /tmp/2 | sed -e 's/<//g' | awk 'BEGIN {ORS=" "} {print $1}'
Breaking it down:
sdiff
checks if there are any new changessed
ensures that you only get the relevant characters, not<
or>
- If you want you can put an
egrep
beforesed
to get only one side of the changes
- If you want you can put an
awk
puts all the lines together into a space separated values that can be fed intopip install