Python offline installation of python3 pip3 and offline installation of your third-party modules

Keywords: Python RPM yum zlib

In the case of many enterprise production networks, servers cannot be connected to the Internet. You can install python and third-party modules offline through the following learning

Install Python 3 dependency package

Off line installation

yum install --downloadonly --downloaddir=/home/files zlib-devel bzip2-devel openssl-devel ncurses-devel  epel-release gcc gcc-c++ xz-devel readline-devel gdbm-devel sqlite-devel tk-devel db4-devel libpcap-devel libffi-devel

cd /home/files  #copy the dependency package to the offline server and enter the directory
rpm -Uvh ./*.rpm --nodeps --force   #Install all rpm dependency packages

Online installation

# The dependency package will be automatically downloaded and installed

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel  epel-release gcc gcc-c++ xz-devel readline-devel gdbm-devel sqlite-devel tk-devel db4-devel libpcap-devel libffi-devel

Download and install python3

Download Python 3.7.2 installation package from centos

wget --no-check-certificate https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
# Will be downloaded to your current directory

You can also download the python 3.7.2 installation package from the web

https://www.python.org/ftp/python/ #Download python installation package

Installing python3.7.2 offline

tar -zxvf Python-3.7.2.tgz  # Unzip the python3 installation package
cd Python-3.7.2     # Enter the python3 installation package directory
./configure --prefix=/usr/local/bin/python3 # Install Python 3 in this directory
make && make install    # Compile and install

Create a soft connection

ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3   # Create a python 3 soft connection
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3 # Create a soft connection for pip3

Installing third-party modules offline in python

Download modules in centos

# If you install a new module, you can download it directly
pip3 download xxx  -d /tmp/packages/

View the installed modules of the server, download and install them to the offline server (migration module)

# pip3 list to view installed modules
[root@localhost py_model]# pip3 list
Package      Version
------------ -------
asn1crypto   0.24.0
bcrypt       3.1.6
cffi         1.12.3
cryptography 2.6.1
paramiko     2.4.2
pip          18.1
pyasn1       0.4.5
pycparser    2.19
PyNaCl       1.3.0
setuptools   40.6.2
six          1.12.0
xlrd         1.2.0
# Document the information of pip3 list
pip3 freeze >requirements.txt
# Download the module information listed in the requirement.txt document to the specified directory
pip3 download -r requirements.txt -d /tmp/packages/  #Recommended use
//Or pip3 install --download /tmp/packages -r requirements.txt
# copy the downloaded module to the offline server
pip3 install xxx.tar.gz
pip3 install xxx.whl
pip3 install xxx.xx  #You can install files of any format.

# If there are multiple packages and dependent packages to install, and you do not know which one to install first, put these files in a directory, and then enter the directory to install them together with the following command

pip3 install ./*
# To batch install the modules in requirements.txt offline, copy the downloaded modules and requirements.txt to a directory, and then execute the following command
pip3 install --no-index --find-links=/tmp/packages  -r requirments.txt 

Posted by devang23 on Fri, 25 Oct 2019 12:40:12 -0700