軟件環境
Python 3.6.8 (很可能 Python2.7.x 也有類似問題)
Win10
問題描述
C:\Users\peterpan\Desktop>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jinja2 Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/ Collecting jinja2 Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out. (read timeout=15)",)': /packages/27/24/4f35961e5c669e96f6559760042a55b9bcfcdb82b9bdb3c8753dbe042e35/Jinja2-2.11.1-py2.py3-none-any.whl Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/24/4f35961e5c669e96f6559760042a55b9bcfcdb82b9bdb3c8753dbe042e35/Jinja2-2.11.1-py2.py3-none-any.whl (126kB) 100% |████████████████████████████████| 133kB 73kB/s Collecting MarkupSafe>=0.23 (from jinja2) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b9/82/833c7714951bff8f502ed054e6fbd8bd00e083d1fd96de6a46905cf23378/MarkupSafe-1.1.1-cp36-cp36m-win_amd64.whl Installing collected packages: MarkupSafe, jinja2 Could not install packages due to an EnvironmentError: [WinError 5] 拒絕訪問。: 'c:\\program files\\python36\\Lib\\site-packages\\markupsafe' Consider using the `--user` option or check the permissions.
問題根源
Win10 對 Python 安裝位置的系統權限限定問題。(導致此問題的原因是,安裝 Python 時沒有勾選 Install for all users)
解決方案一
僅安裝給 current user 使用
C:\Users\peterpan\Desktop>pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple/ jinja2
安裝包會安裝在 C:\Users\peterpan\AppData\Roaming\Python\Python36\site-packages 下。
解決方案二
修改文件夾 C:\Program Files\Python36\Lib\site-packages 權限,讓其獲得讀寫權限,然后就可以直接安裝
C:\Users\peterpan\Desktop>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jinja2
安裝包會安裝在 C:\Program Files\Python36\Lib\site-packages 下。
完。