[CF1284D] New Year and Conference - 掃描線
最近運維上需要在測試環境呼叫http的post請求,實現自動化日切,我看了下我會的程式設計,也就python能符合我的要求,且簡單好操作。但是在實際操作過程遇到了一些問題,其中最大的就是測試環境的機器是外網隔離的,沒法連外網進行直接安裝部分模組,通過搜尋和實踐之後,簡單說下我的經驗。
機器環境
作業系統:Windows Server 2012 x64
python3安裝
從 [官網] 下載最新的適合windows 的安裝包。
下載下來的python-3.7.4-amd64.exe,直接拷貝到測試環境的機器上,雙擊安裝即可,需要注意的是,最好勾選 AddPython 3.7 to PATH,這樣後期直接在cmd視窗中就可以呼叫python命令了。
requests模組的依賴包檢查
在可以上網且已安裝python的機器上檢查requests模組需要哪些依賴包,要是沒有依賴包,直接下載一個直接安裝最好。
在CMD命令視窗中輸入 pip show requests
C:\Users\Laycher>pip show requests Name: requests Version: 2.18.4 Summary: Python HTTP for Humans. Home-page: http://python-requests.org Author: Kenneth Reitz Author-email: [email protected] License: Apache 2.0 Location: d:\program files\python3\lib\site-packages Requires: chardet, urllib3, idna, certifi Required-by:
發現需要chardet,urllib3,idna,certifi
下載依賴包模組和requests模組
在網站 https://www.lfd.uci.edu/~gohlke/pythonlibs 上找到相應的程式,下載。
certifi-2019.9.11-py2.py3-none-any.whl chardet-3.0.4-py2.py3-none-any.whl idna-2.8-py2.py3-none-any.whl requests-2.22.0-py2.py3-none-any.whl urllib3-1.25.6-py2.py3-none-any.whl
安裝模組
將以上下載的檔案傳到測試環境。離線裝模組。
安裝命令為 pip install XXXXX.whl
切記,先安裝依賴包,如果直接安裝requests,由於有依賴包,還是會去連外網找依賴包。
D:\軟體>pip install certifi-2019.9.11-py2.py3-none-any.whl Processing d:\軟體\certifi-2019.9.11-py2.py3-none-any.whl Installing collected packages: certifi Successfully installed certifi-2019.9.11 D:\軟體>pip install chardet-3.0.4-py2.py3-none-any.whl Processing d:\軟體\chardet-3.0.4-py2.py3-none-any.whl Installing collected packages: chardet Successfully installed chardet-3.0.4 D:\軟體>pip install idna-2.8-py2.py3-none-any.whl Processing d:\軟體\idna-2.8-py2.py3-none-any.whl Installing collected packages: idna Successfully installed idna-2.8 D:\軟體>pip install urllib3-1.25.6-py2.py3-none-any.whl Processing d:\軟體\urllib3-1.25.6-py2.py3-none-any.whl Installing collected packages: urllib3 Successfully installed urllib3-1.25.6 D:\軟體>pip install requests-2.22.0-py2.py3-none-any.whl Processing d:\軟體\requests-2.22.0-py2.py3-none-any.whl Requirement already satisfied: idna in c:\users\administrator\appdata\local\prog rams\python\python37\lib\site-packages (from requests==2.22.0) (2.8) Requirement already satisfied: chardet in c:\users\administrator\appdata\local\p rograms\python\python37\lib\site-packages (from requests==2.22.0) (3.0.4) Requirement already satisfied: urllib3 in c:\users\administrator\appdata\local\p rograms\python\python37\lib\site-packages (from requests==2.22.0) (1.25.6) Requirement already satisfied: certifi in c:\users\administrator\appdata\local\p rograms\python\python37\lib\site-packages (from requests==2.22.0) (2019.9.11) Installing collected packages: requests Successfully installed requests-2.22.0
安裝包彙集
我彙集了我這邊的安裝包,[點此下載 ]
其他辦法
網上還有很多其他辦法,比如在乾淨的能上外網的機器上,安裝python,然後pip install 安裝需要的模組,然後直接把python安裝目錄直接拷到離線環境中,那就直接可以用了。
還有的是通過命令 pip freeze > requiresment.txt ,生成已經安裝的模組資訊,然後再下載。具體可以搜尋看看。
總結
以上所述是小編給大家介紹的Python3離線安裝Requests模組問題,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回覆大家的!