Python - PIP 安装疑难解答 - PermissionError: [WinError 5] 访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32167418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python - PIP install trouble shooting - PermissionError: [WinError 5] Access is denied
提问by Dave Mansfield
I get the following error when using PIP to either install new packages or even upgrade pip itself to the latest version. I am running pip on a windows 8.1 machine with Python 3.4.
使用 PIP 安装新软件包甚至将 pip 本身升级到最新版本时,我收到以下错误。我正在使用 Python 3.4 的 Windows 8.1 机器上运行 pip。
The message is telling me I don't have Administrative Permission on the files (my account is an Administrator Account).
该消息告诉我我没有文件的管理权限(我的帐户是管理员帐户)。
I would appreciate any thoughts on how to resolve this, as it is getting in the way of installing packages and progressing with Python.
我很感激关于如何解决这个问题的任何想法,因为它妨碍了安装包和使用 Python 的进展。
Error message:
错误信息:
Installing collected packages: pip
Found existing installation: pip 6.0.8
Uninstalling pip-6.0.8:
Removing file or directory c:\program files (x86)\python\python34\lib\site-packages\pip-6.0.8.dist-info\description.rst
Cleaning up...
Exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python\Python34\lib\shutil.py", line 523, in move
os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'c:\program files (x86)\python\python34\lib\site-packages\pip-6.0.8.dist-info\description.rst' -> 'C:\Users\User\AppData\Local\Temp\pip-uze_sc4k-uninstall\program files (x86)\python\python34\lib\site-packages\pip-6.0.8.dist-info\description.rst'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\basecommand.py", line 232, in main
status = self.run(options, args)
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\commands\install.py", line 347, in run
root=options.root_path,
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_set.py", line 543, in install
requirement.uninstall(auto_confirm=True)
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_install.py", line 667, in uninstall
paths_to_remove.remove(auto_confirm)
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\req\req_uninstall.py", line 126, in remove
renames(path, new_path)
File "C:\Program Files (x86)\Python\Python34\lib\site-packages\pip\utils\__init__.py", line 316, in renames
shutil.move(old, new)
File "C:\Program Files (x86)\Python\Python34\lib\shutil.py", line 536, in move
os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'c:\program files (x86)\python\python34\lib\site-packages\pip-6.0.8.dist-info\description.rst'
回答by Roope
E: Since this answer seems to have gained some popularity, I will add: doing things globally is most of the time not a great idea. Almost always the correct answer is: use a project environment where you're not installing things globally, e.g. with virtualenv
.
E:由于这个答案似乎已经获得了一些人气,我要补充一点:在大多数情况下,在全球范围内做事并不是一个好主意。几乎总是正确的答案是:使用不全局安装东西的项目环境,例如使用virtualenv
.
For those that may run into the same issue:
对于那些可能遇到同样问题的人:
Run the command prompt as administrator. Having administrator permissions in the account is not always enough. In Windows, things can be run as administrator by right-clicking the executable and selecting "Run as Administrator". So, type "cmd" to the Start menu, right click cmd.exe, and run it as administrator.
以管理员身份运行命令提示符。在帐户中拥有管理员权限并不总是足够的。在 Windows 中,可以通过右键单击可执行文件并选择“以管理员身份运行”来以管理员身份运行。因此,在开始菜单中键入“cmd”,右键单击 cmd.exe,然后以管理员身份运行它。
回答by Santa
Do not use the command prompt in the IDE. Run the command prompt from windows as an administrator. I'm sure this will solve the problem. If not, uninstall pip and reinstall the latest one directly.
不要在 IDE 中使用命令提示符。以管理员身份从 Windows 运行命令提示符。我相信这会解决问题。如果不行,直接卸载pip,重新安装最新的。
回答by Valerij
As of upgrading from pip 7.x.x to 8.x.x on Python 3.4 (for *.whl support).
在 Python 3.4 上从 pip 7.xx 升级到 8.xx(用于 *.whl 支持)。
Wrong command:
pip install --upgrade pip
(can't move pip.exe to temporary folder, permisson denied)
错误的命令:(
pip install --upgrade pip
无法将 pip.exe 移动到临时文件夹,权限被拒绝)
OK variant:
py -3.4 -m pip install --upgrade pip
(do not execute pip.exe)
OK变体:(
py -3.4 -m pip install --upgrade pip
不执行pip.exe)
回答by Netzsooc
I have had the same problem with anaconda on windows. It seems that there is an issu with mcAfee antivirus. If you deactivate it while running the updates or the installs, it allows you to properly run the installation.
我在 Windows 上遇到了与 anaconda 相同的问题。mcAfee 防病毒软件似乎存在问题。如果在运行更新或安装时停用它,它允许您正确运行安装。
回答by JKC
I know my answer would be weird but that's what I have experienced just now.
我知道我的回答会很奇怪,但这就是我刚才所经历的。
I got the similar error when installing tensorflow package and I tried the same by opening powershell in windows as administrator but in vain.
我在安装 tensorflow 包时遇到了类似的错误,我通过在 Windows 中以管理员身份打开 powershell 尝试了同样的错误,但没有成功。
Later I found out that I was already using numpy in one of the python scripts in an active python session. So I closed the Spyder IDE and tried to install the tensorflow package by running powershell as administrator and it worked.
后来我发现我已经在活动的 python 会话中的一个 python 脚本中使用了 numpy。所以我关闭了 Spyder IDE 并尝试通过以管理员身份运行 powershell 来安装 tensorflow 包并且它工作正常。
Hope this will help somebody else like me who will open this older but useful post in upcoming days
希望这会帮助像我这样的人,他们将在未来几天内打开这篇较旧但有用的帖子
回答by Mike 'Pomax' Kamermans
Still relevant in 2018: don't install packages as admin.
在 2018 年仍然相关:不要以管理员身份安装软件包。
The by farmore sensible solution is to use virtualenvto create a virtual environment directory (virtualenv dirname
) and then activate that virtual environment with dirname\Script\Activate
in Windows before running any pip commands. Or use pipenvto manage the installs for you.
在目前更明智的解决方案是使用的virtualenv创建虚拟环境目录(virtualenv dirname
),然后激活虚拟环境与dirname\Script\Activate
在Windows中运行任何点子命令之前。或者使用pipenv为您管理安装。
That way, everything gets written to dirs that you have full write permission for, without needing UAC, and without global installs for local directories.
这样,所有内容都会写入您拥有完全写入权限的目录,无需 UAC,也无需为本地目录进行全局安装。
回答by Michael Martin
For those who run into this issue and running the command prompt as administrator does not workthis worked for me:
对于遇到此问题并以管理员身份运行命令提示符的人来说,这对我不起作用:
Since I had already tried a first time without running the cmd prompt as admin, in my c:\Users\"USER"\AppData\Local\Tempfolder I found it was trying to run files from the same pip-u2e7e0ad-uninstallfolder. Deleting this folder from the Tempfolder and retrying the installation fixed the issue for me.
由于我已经第一次尝试在没有以管理员身份运行 cmd 提示符的情况下,在我的c:\Users\"USER"\AppData\Local\Temp文件夹中,我发现它正在尝试运行来自同一个pip-u2e7e0ad-uninstall文件夹的文件. 从Temp文件夹中删除此文件夹并重试安装解决了我的问题。
回答by davetunes
I had this issue as well on Windows 10. Closing all my Jupyter Notebook sessions and re-running the pip install --upgrade
commands as an administrator made the issue go away.
我在 Windows 10 上也遇到了这个问题。关闭我所有的 Jupyter Notebook 会话并pip install --upgrade
以管理员身份重新运行命令使问题消失了。
回答by Wyrmwood
After seeing
看过之后
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
I ran
我跑了
pip install -U pip
and hit this error
并遇到此错误
PermissionError: [WinError 5]
I tried again and got
我再次尝试并得到
pip install -U pip
ERROR: To modify pip, please run the following command:
c:\python36-32\python.exe -m pip install -U pip
After running that exact command, it worked.
运行该确切命令后,它起作用了。
For those promoting the use of virtual environments as a solution to this error, pip and virtualenv must be updated in your main install. Simply put, a virtual environment offers no solution to this problem.
对于那些提倡使用虚拟环境作为解决此错误的方法的人,必须在主安装中更新 pip 和 virtualenv。简而言之,虚拟环境无法解决这个问题。
回答by Zeinab
Simply, Run the cmd in Administrator mode.
简单地说,在管理员模式下运行 cmd。