使用 PIP (Python Package Installer) 安裝 Python 套件遇到 SSLCertVerificationError 錯誤,無法安裝套件。解決方式是安裝 OpenSSL。
問題狀況
Windows 剛安裝好 Python 3.9.3 ,要安裝新套件時,遇到以下錯誤訊息:
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)'))': /simple/cloudscraper/
Could not fetch URL https://pypi.org/simple/cloudscraper/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/cloudscraper/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)'))) - skipping
解決方式
安裝 OpenSSL,網路教學有許多 Windows 安裝方式,以下是使用 Windows 套件管理工具 Chocolatey 安裝 OpenSSL
1. Windows 程式集尋找 「命令提示字元」或左下角輸入 cmd 快速搜尋
2. 將滑鼠游標移到「命令提示字元」上方,選擇「以系統管理員身份執行」
3. 到 Chocolatey 網站 Setup / Install 網頁,複製及輸入以下的安裝 Chocolatey 指令:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
4. 安裝完 Chocolatey 後,到 Chocolatey 網站 OpenSSL 1.1.1.1100 網頁,複製及輸入以下安裝 OpenSSL 指令:
choco install openssl
過程中會詢問要不要安裝相依套件,可輸入 A 代表同意安裝所有相依套件
5. 直到出現在套件完成畫面,再重新開機即可
6. 開機後,使用 PIP 安裝套件就不會遇到 SSLCertVerificationError 錯誤
無效的嘗試
使用 --trusted 參數 也無效
# pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org cloudscraper
Looking in indexes: http://pypi.python.org/simple/
ERROR: Could not find a version that satisfies the requirement cloudscraper (from versions: none)
ERROR: No matching distribution found for cloudscraper
版本資訊
# python --versionPython 3.9.4# pip --versionpip 20.2.3
參考資料
- Troubleshooting — python-for-android 0.1 documentation
- ssl - How to install OpenSSL in windows 10? - Stack Overflow
- 問題 28150: Error CERTIFICATE_VERIFY_FAILED in macOS - Python tracker
- python - macOS pyenv: pip install not working [SSL: CERTIFICATE_VERIFY_FAILED] - Stack Overflow
- python - "SSL: CERTIFICATE_VERIFY_FAILED" error while using PIP - Stack Overflow
- installation - Python: cannot install packages with pip - Stack Overflow
- Pip Install - SSL Error: Certificate_Verify_Failed - ShellHacks
留言
張貼留言