pip
升级它自身,可能会遇到一个神秘的“访问被拒绝”错误。例如:D:\scratch\> C:\Program Files\Python\3.7.4\x64\python.exe -m venv D:\scratch\my-venv
D:\scratch\> D:\scratch\my-venv\Scripts\activate
(my-venv) D:\scratch\> pip install --upgrade pip
Collecting pip
Downloading pip-19.3.1-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
Found existing installation: pip 19.0.3
Uninstalling pip-19.0.3:
Could not install packages due to an EnvironmentError:
[WinError 5] Access is denied: 'd:\\scratch\\my-venv\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.
无论命令提示符是否具有管理员特权,都会发生这种情况。 我们知道我们对
d:\scratch\my-venv
中的所有内容都具有写访问权限,因为我们刚刚使用最初的python -m venv
命令创建了它。建议使用 --user
选项是无用的,因为我们想要升级虚拟环境中的pip版本,而--user
不会做到。
有什么问题,以及在Windows上升级虚拟环境中的pip的正确方法是什么?