Install python packages offline on server

sahand1372 picture sahand1372 · Jan 16, 2019 · Viewed 14.5k times · Source

I want to install some packages on the server which does not access to internet. so I have to take packages and send them to the server. But I do not know how can I install them.

Answer

machnic picture machnic · Jan 16, 2019

Download all the packages you need and send them to the server where you need to install them. It doesn't matter if they have *whl or *tar.gz extension. Then install them one by one using pip:

pip install path/to/package

or:

python -m pip install path/to/package

The second option is useful if you have multiple interpreters on the server (e.g. python2 and python3 or multiple versions of either of them). In such case replace python with the one you want to use, e.g:

python3 -m pip install path/to/package

If you have a lot of packages, you can list them in a requirement file as you would normally do when you have access to the internet. Then instead of putting the names of the packages into the file, put the paths to the packages (one path per line). When you have the file, install all packages by typing:

python -m pip install -r requirements.txt

In the requirements file you can also mix between different types of the packages (*whl and *tar.gz). The only thing to take care about is to download the correct versions of the packages you need for the platform you have (64bit packages for 64bit platform etc.).

You can find more information regarding pip install in its documentation.