机器A:能联网
机器B:内网
机器A:
-
在python虚拟环境中安装需要的第三方库
[root@i-h0xe1oiq data]# mkvirtualenv -p /usr/local/bin/python3.9 env39 (env39) [root@i-h0xe1oiq data]# pip3.9 install pymysql (env39) [root@i-h0xe1oiq data]# pip3.9 install requests
-
导出第三方库名到文件
(env39) [root@i-h0xe1oiq data]# pip3.9 freeze >requirements.txt (env39) [root@i-h0xe1oiq data]# cat requirements.txt certifi==2021.10.8 charset-normalizer==2.0.7 idna==3.3 PyMySQL==1.0.2 requests==2.26.0 urllib3==1.26.7
-
下载离线包
(env39) [root@i-h0xe1oiq data]# pip3.9 download -d packages -r requirements.txt (env39) [root@i-h0xe1oiq data]# ll total 8 drwxr-xr-x 2 root root 4096 Oct 20 16:22 packages -rw-r--r-- 1 root root 103 Oct 20 16:21 requirements.txt (env39) [root@i-h0xe1oiq data]# ll packages/ # 下载的包都在packages目录下 total 492 -rw-r--r-- 1 root root 149195 Oct 20 16:22 certifi-2021.10.8-py2.py3-none-any.whl -rw-r--r-- 1 root root 38247 Oct 20 16:22 charset_normalizer-2.0.7-py3-none-any.whl -rw-r--r-- 1 root root 61160 Oct 20 16:22 idna-3.3-py3-none-any.whl -rw-r--r-- 1 root root 43828 Oct 20 16:22 PyMySQL-1.0.2-py3-none-any.whl -rw-r--r-- 1 root root 62251 Oct 20 16:22 requests-2.26.0-py2.py3-none-any.whl -rw-r--r-- 1 root root 138764 Oct 20 16:22 urllib3-1.26.7-py2.py3-none-any.whl
-
将packages目录和requirements.txt文件复制到机器B上
机器B:
-
安装第三方库
[root@VM-8-6-centos data]# pip3.6 install --no-index --find-links=packages -r requirements.txt Collecting certifi==2021.10.8 (from -r requirements.txt (line 1)) Collecting charset-normalizer==2.0.7 (from -r requirements.txt (line 2)) Collecting idna==3.3 (from -r requirements.txt (line 3)) Collecting PyMySQL==1.0.2 (from -r requirements.txt (line 4)) Collecting requests==2.26.0 (from -r requirements.txt (line 5)) Collecting urllib3==1.26.7 (from -r requirements.txt (line 6)) Installing collected packages: certifi, charset-normalizer, idna, PyMySQL, urllib3, requests Successfully installed PyMySQL-1.0.2 certifi-2021.10.8 charset-normalizer-2.0.7 idna-3.3 requests-2.26.0 urllib3-1.26.7