Win10 环境下 pip 安装失败的问题“Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。”
软件环境
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 下。
完。