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: https://developers.redhat.com/blog/2018/08/13/install-python3-rhel)
- 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 https://files.pythonhosted.org/packages/06/1e/1e08baaaf6c3d3df1459fd85f0
e7d2d6aa916f33958f151ee1ecc9800971/paramiko-2.7.1-py2.py3-none-any.whl
Saved ./paramiko-2.7.1-py2.py3-none-any.whl
Collecting bcrypt>=3.1.3 (from paramiko)
Using cached https://files.pythonhosted.org/packages/8b/1d/82826443777dd4a624e38a0
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 https://files.pythonhosted.org/packages/58/95/f1282ca55649b60afcf617e
1e2ca384a2a3e7a5cf91f724cf83c8fbe76a1/cryptography-2.9.2-cp35-abi3-manylinux1_x86_64.whl
Saved ./cryptography-2.9.2-cp35-abi3-manylinux1_x86_64.whl
Collecting pynacl>=1.0.1 (from paramiko)
Downloading https://files.pythonhosted.org/packages/9d/57/2f5e6226a674b2bcb6db531e8b3
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 https://files.pythonhosted.org/packages/f1/c7/72abda280893609e1ddfff90f80
64568bd8bcb2c1770a9d5bb5edb2d1fea/cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.wh
Saved ./cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting six>=1.4.1 (from bcrypt>=3.1.3->paramiko)
Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b03
16ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Saved ./six-1.15.0-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko)
Using cached https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf8234
2dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl
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!

Trackbacks

No Trackbacks

Comments

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.