Skip to content

Installing Python Modules to an Offline Linux Server

In this article I will describe how to install Python modules to an offline server. Example will show how to use Pip to download packages in an online server and then install those locally in an offline server.

Following prerequirements are assumed for this example:

- Python 3.6 and PIP installed (this document shows a way:
- Offline target server is accessible and you can transfer files there
- Online server with Internet access

Following steps are required to download Python modules in an online computer, then move those to the offline computer and install those locally with Pip. In this example, my goal is to install Paramiko for SSH connectivity and all other required modules. Packages that can be installed through Pip can be found from PyPi documentation.

1. Use Pip to download modules on the online computer


Downloading packages with Pip is as simple as "pip download [package-name]"

[root@localhost ~]# pip download paramiko
Collecting paramiko
Using cached
Saved ./paramiko-2.7.1-py2.py3-none-any.whl
Collecting bcrypt>=3.1.3 (from paramiko)
Using cached
8957b975e75df859b381ae302cfd7a30783ed/bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.wh l
Saved ./bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl
Collecting cryptography>=2.5 (from paramiko)
Using cached
Saved ./cryptography-2.9.2-cp35-abi3-manylinux1_x86_64.whl
Collecting pynacl>=1.0.1 (from paramiko)
83079b678df5b10cdaa610d6cf20d77ba/PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961kB)
100% |████████████████████████████████| 962kB 1.2MB/s
Saved ./PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl
Collecting cffi>=1.1 (from bcrypt>=3.1.3->paramiko)
Using cached
Saved ./cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting six>=1.4.1 (from bcrypt>=3.1.3->paramiko)
Saved ./six-1.15.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko)
Using cached
Saved ./pycparser-2.20-py2.py3-none-any.whl
Successfully downloaded paramiko bcrypt cryptography pynacl cffi six pycparser

As observed, Pip downloaded other necessary packages too: bcrypt cryptography pynacl cffi six pycparser. Package files are in the working directory.

2. Pack .whl files and move them to the target computer

Use tar to pack the files and move them to the target computer, I used RDP over Citrix to copy these.

[root@localhost ~]# tar cvf paramiko.tar /root/*.whl

3. Unpack .whl files in the target computer

[root@localhost ~]# tar xf /root/paramiko.tar -C /root/paramiko/
[root@localhost ~]# ls -al /root/paramiko/
total 4380
drwxr-xr-x. 2 root root 4096 Jun 1 14:45 .
dr-xr-x---. 8 root root 4096 Jun 1 14:45 ..
-rw-r--r--. 1 root root 56080 Jun 1 14:40 bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl
-rw-r--r--. 1 root root 399201 Jun 1 14:40 cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl
-rw-r--r--. 1 root root 2718247 Jun 1 14:40 cryptography-2.9.2-cp35-abi3-manylinux1_x86_64.whl
-rw-r--r--. 1 root root 206798 Jun 1 14:40 paramiko-2.7.1-py2.py3-none-any.whl
-rw-r--r--. 1 root root 112041 Jun 1 14:40 pycparser-2.20-py2.py3-none-any.whl
-rw-r--r--. 1 root root 961075 Jun 1 14:40 PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl
-rw-r--r--. 1 root root 10963 Jun 1 14:40 six-1.15.0-py2.py3-none-any.whl

4. Use Pip to install packages - note that they need to be installed in the correct order :-)

As in the example, no-index and find-links parameters are used as we want to install local packages and not from wheel cache. More information can be found from Pip documentation: no-index find-links Pip User Guide

[root@localhost ~]# pip install /root/root/pycparser-2.20-py2.py3-none-any.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/six-1.14.0-py2.py3-none-any.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/cryptography-2.9.2-cp35-abi3-manylinux1_x86_64.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/PyNaCl-1.3.0-cp34-abi3-manylinux1_x86_64.whl --no-index --find-links '.'
[root@localhost ~]# pip install /root/root/paramiko-2.7.1-py2.py3-none-any.whl --no-index --find-links '.'
[root@localhost ~]# pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
bcrypt (3.1.7)
cffi (1.14.0)
cryptography (2.9.2)
paramiko (2.7.1)
pip (9.0.1)
pycparser (2.20)
PyNaCl (1.3.0)
setuptools (36.5.0)
six (1.14.0)
virtualenv (15.1.0)

Pip list confirms that packages are now installed and you can use Paramiko in your scripts now!


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
Form options

Submitted comments will be subject to moderation before being displayed.