Python uses PIP free and dowload to print offline packages and install them automatically [suitable for confidential offline environment]

Time:2021-3-21

Pip of Python is its package management tool, which is quite convenient and easy to use. This article only introduces how PIP can use its softwarefreezeCommand to print the offline package and its installation script. This knowledge point is especially applicable to devices that are not suitable for connecting to the Internet and need to be physically isolated,Strict confidentiality requirementsCustomer environment.

 

Environmental Science

Operating system: Centos 7.7

Python version: 2.7

Customer network environment: offline

R & D network environment: Networking

 

  • PIP installation

(1)Download RPM package

First, research and development environment (Networking), tohttps://pkgs.org/download/python-pipSelect the appropriate PIP RPM offline package to download, as shown in the figure below:

Select an RPM link, click in, and then in the download module, select the binary file related download address to download【CoderBaby】, as shown in the figure below:

 

 (2) RPM install PIP offline package

rpm -ivh python2-pip-8.1.2-10.el7. noarch.rpm (RPM) offline packageFull pathname

 

(3) Upgrade pip

Upgrade pip to the latest version through the old version of PIP install command, as follows:

pip install packages/pip-20.2.3-py2.py3-none- any.whl (download from pypi website).whlPackage:https://pypi.org/project/pip/#files

 

(4) PIP freeze packages the installed packages in the required format

The specific orders are as follows:

pip freeze > requirements.txt (redirect, and specify the output file name, format, and path)

The results are as follows

 

(5) PIP download download offline package

The specific orders are as follows:

pip download -d packages -r requirements.txt (will) requirements.txt The package name and version specified in the requirements.txt , delete packages that do not need to be packaged] and package them in the default packages folder.)

The results are as follows:

 

(6) Install offline package through shell script

The specific shell script commands are as follows:

pip install –no-index –find-links=packages -r requirements.txt 

explain:

First, the packages folder and requirements.txt Copy to offline server: put the packages folder in any directory, requirements.txt Put it in the same level directory

The related directory structure is as follows:

 

Note:

  • Upgrade Python 2.6.6 to 2.7

centos 6 The built-in Python version is 2.6.6, which needs to be upgraded to 2.7. For details, please refer to:https://www.cnblogs.com/gjc592/p/9223005.html 

【@2020/12/7CentOS 6 has been abandoned by major domestic imagesBecause as of November 30, 2020, centos6 has stopped maintenance and update. See:https://www.v2ex.com/t/733142