Install python third-party libraries in an offline environment

python offline environment install python third-party library
author: yafeishi
tags: AntDB,python

Python is really convenient for operation and maintenance work, but many of the more practical libraries are provided by third parties, which are not in the iso that comes with os. Installing third-party libraries in an offline environment is a very painful thing, and there is no end to it. Dependencies will break you. Is it possible to solve the dependency problem through pip in an offline environment like an online environment? The answer is yes (it's impossible for me to install dependencies one by one, it's impossible in this life).

Take the installation of paramiko in an offline environment as an example:
Although paramiko is easy to use, it has a lot of dependencies, so much that I want to give up using it until I find a way to solve dependencies with pip offline installation, and I feel that the world is full of sunshine again.
The general idea is:
1. Install setuptools and pip in the offline environment
2. In the online environment, download the dependencies of paramiko to a folder
through pip 3. In the offline environment, access the folder through pip to solve the dependency problem and install it smoothly .

First, in an offline environment, setuptools and pip need to be installed:

unzip setuptools-39.1.0.zip
cd setuptools-39.1.0 && $SUDO python setup.py install
cd ..
tar xzvf pip-10.0.1.tar.gz
cd pip-10.0.1 && $SUDO python setup.py install
cd ..

In an online environment, download paramiko's dependencies:

pip download -d /tmp/paramiko paramiko
tar zcvf paramiko.tar.gz /tmp/paramiko

Upload paramiko.tar.gz to the offline environment and install it through pip in the offline environment:

tar xzvf paramiko.tar.gz 
pip install --no-index --ignore-installed six --find-links=tmp/paramiko paramiko

[root@adb01 ~]# pip install --no-index --ignore-installed six --find-links=tmp/paramiko paramiko
Looking in links: tmp/paramiko
Collecting six
Collecting paramiko
Collecting pyasn1>=0.1.7 (from paramiko)
Collecting bcrypt>=3.1.3 (from paramiko)
Collecting cryptography>=1.5 (from paramiko)
Collecting pynacl>=1.0.1 (from paramiko)
Collecting cffi>=1.1 (from bcrypt>=3.1.3->paramiko)
Collecting idna>=2.1 (from cryptography>=1.5->paramiko)
Collecting enum34; python_version < "3" (from cryptography>=1.5->paramiko)
Collecting ipaddress; python_version < "3" (from cryptography>=1.5->paramiko)
Collecting asn1crypto>=0.21.0 (from cryptography>=1.5->paramiko)
Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko)
Installing collected packages: six, pyasn1, pycparser, cffi, bcrypt, idna, enum34, ipaddress, asn1crypto, cryptography, pynacl, paramiko
  Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.5 cryptography-2.2.2 enum34-1.1.6 idna-2.6 ipaddress-1.0.22 paramiko-2.4.1 pyasn1-0.4.2 pycparser-2.18 pynacl-1.2.1 six-1.11.0
You have mail in /var/spool/mail/root
[root@adb01 ~]# python -c 'import paramiko'
[root@adb01 ~]# 

As you can see from the final result, paramiko has been successfully installed.

After this problem is solved, I can happily introduce python packages into AntDB to expand the operation and maintenance tools.

Reference link:
https://pip.pypa.io/en/stable/reference/pip_download/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325305471&siteId=291194637
Recommended