Create a local Python pip repository

Oct 1, 2019 by Alexandre Croix | 21847 views


Python is a very interesting programming language because it is possible to prototype a lot of things in a few minutes. The Python Package manager, called pip, is a very simple tool that allows the user to import/install easily any Python package and its dependencies.

Sometimes, it is necessary to use Python on an offline computer. In this situation, it is not possible to install Python packages from the official repository (

To avoid this problem, it is possible to install your own repository on any machine.

Install Apache on an offline computer

The first step to set up a local Python repository is to install an Apache server.

If it is possible to install Apache with an Internet connection, use simply:

sudo apt-get install apache2

If it is not allowed or possible to connect the computer on the Internet, you have to install apache manually. The following script download all needed dependencies:

wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c

Copy them on the offline computer and install them manually.

Create local pip repository

If you need only some specific dependencies, pypi-mirror ( is the perfect tool. Install, on an online computer, pypi-mirror (works only with pip3):

pip install python-pypi-mirror

Then, run the two following commands for each your required dependencies:

pypi-mirror download -d path/to/folder <package>
pypi-mirror create -c -d path/to/folder -m simple

The first command will download the Python package and its dependencies on the folder path/to/folder. The second command will create an index of the dependencies and store it in the simple folder.

For a large number of dependencies, it could be interesting to use a script to read and download all dependencies from a requirements.txt file.

Copy the path/to/folder and simple folders in /var/www/html on the offline machine. The local repository is ready!

Use your local repository

To use your new local repository on this offline machine (or any machine connected to the same local network), use the following command:

pip install -i http://ip.of.srv/simple --trusted-host ip.of.srv package

Of course,pip must be installed on the offline computer on which you want to install the package. It is possible to do it manually (as for the Apache server), or, longer but easier, use a local apt-mirror as described:

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.