這里以下載requests模塊為例
1、創建存放模塊的目錄
[root@python-mysql requests_dir]# mkdir /root/requests_dir/
2、准備下載離線模塊
[root@python-mysql requests_dir]# pip3 download -d /root/requests_dir requests==2.22.0 Collecting requests==2.22.0 Using cached https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl Saved ./requests-2.22.0-py2.py3-none-any.whl Collecting chardet<3.1.0,>=3.0.2 (from requests==2.22.0) Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl Saved ./chardet-3.0.4-py2.py3-none-any.whl Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests==2.22.0) Using cached https://files.pythonhosted.org/packages/b4/40/a9837291310ee1ccc242ceb6ebfd9eb21539649f193a7c8c86ba15b98539/urllib3-1.25.7-py2.py3-none-any.whl Saved ./urllib3-1.25.7-py2.py3-none-any.whl Collecting idna<2.9,>=2.5 (from requests==2.22.0) Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl Saved ./idna-2.8-py2.py3-none-any.whl Collecting certifi>=2017.4.17 (from requests==2.22.0) Using cached https://files.pythonhosted.org/packages/b9/63/df50cac98ea0d5b006c55a399c3bf1db9da7b5a24de7890bc9cfd5dd9e99/certifi-2019.11.28-py2.py3-none-any.whl Saved ./certifi-2019.11.28-py2.py3-none-any.whl Successfully downloaded requests chardet urllib3 idna certifi You are using pip version 10.0.1, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
3、查看下載的模塊
[root@python-mysql requests_dir]# ll /root/requests_dir/ total 532 -rw-r--r-- 1 root root 156030 Dec 25 16:35 certifi-2019.11.28-py2.py3-none-any.whl -rw-r--r-- 1 root root 133356 Dec 25 16:35 chardet-3.0.4-py2.py3-none-any.whl -rw-r--r-- 1 root root 58594 Dec 25 16:35 idna-2.8-py2.py3-none-any.whl -rw-r--r-- 1 root root 57952 Dec 25 16:35 requests-2.22.0-py2.py3-none-any.whl -rw-r--r-- 1 root root 125624 Dec 25 16:35 urllib3-1.25.7-py2.py3-none-any.whl
4、拷貝到不能上網的服務器安裝
#解壓軟件進入目錄 [root@filestore-v2 requests_dir]# tar xvf requests_dir.tar.gz && cd requests_dir #安裝requests模塊以及依賴模塊 [root@filestore-v2 requests_dir]# pip3 install urllib3-1.25.7-py2.py3-none-any.whl idna-2.8-py2.py3-none-any.whl chardet-3.0.4-py2.py3-none-any.whl certifi-2019.11.28-py2.py3-none-any.whl requests-2.22.0-py2.py3-none-any.whl Processing ./urllib3-1.25.7-py2.py3-none-any.whl Processing ./idna-2.8-py2.py3-none-any.whl Processing ./chardet-3.0.4-py2.py3-none-any.whl Processing ./certifi-2019.11.28-py2.py3-none-any.whl Processing ./requests-2.22.0-py2.py3-none-any.whl Installing collected packages: urllib3, idna, chardet, certifi, requests Successfully installed certifi-2019.11.28 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.7 #測試是否安裝成功 [root@filestore-v2 requests_dir]# python3 Python 3.6.6 (default, Dec 25 2019, 15:40:39) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests #<==無報錯,表示安裝成功 >>>