Python Windows 上的 pip 安装访问被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31172719/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:36:22  来源:igfitidea点击:

pip install access denied on Windows

pythonwindowspipaccess-denied

提问by Bruno Klein

I am trying to run pip install mitmproxyon Windows, but I keep getting access denied, even with cmdand PowerShellusing the Run as Administratoroption.

我正在尝试pip install mitmproxy在 Windows上运行,但我一直拒绝访问,即使使用cmdPowerShell使用该Run as Administrator选项也是如此。

WindowsError: [Error 5] Access is denied: 'c:\users\bruno\appdata\local\temp\easy_install-0fme6u\cryptography-0.9.1\.eggs\cffi-1.1.2-py2.7-win-amd64.egg\_cffi_backend.pyd'

How can I make this work?

我怎样才能使这项工作?

采纳答案by nayak

In case of windows, in cmd try to run pip install using python executable

在 Windows 的情况下,在 cmd 中尝试使用 python 可执行文件运行 pip install

e.g.

例如

python -m pip install mitmproxy

this should work, at least it worked for me for other package installation.

这应该有效,至少它对我的其他软件包安装有效。

回答by Felix

Try to delete the folder c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6umanually and then retry the pip command.

尝试c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u手动删除文件夹,然后重试 pip 命令。

回答by Richard Kenneth Niescior

Change your Python installation folder's security permissions by:

通过以下方式更改 Python 安装文件夹的安全权限:

  1. Open a Python shell
  2. Go to task manager
  3. Find the python process
  4. Right-click and open location
  5. The folder will open in explorer, go up a directory
  6. Right-click the folder and select properties
  7. Click the security tab and hit 'edit'
  8. Add everyone and give them permission to Read and Write.
  9. Save your changes
  1. 打开 Python 外壳
  2. 进入任务管理器
  3. 找到python进程
  4. 右键单击并打开位置
  5. 该文件夹将在资源管理器中打开,进入一个目录
  6. 右键单击文件夹并选择属性
  7. 单击安全选项卡并点击“编辑”
  8. 添加所有人并授予他们读写权限。
  9. 保存您的更改

If you open cmdas admin; then you can do the following:

如果您cmd以管理员身份打开;那么您可以执行以下操作:

If Python is set in your PATH, then:

如果在您的 中设置了 Python PATH,则:

python -m pip install mitmproxy

回答by Bhoom Suktitipat

Personally, I found that by opening cmdas adminthen run python -m pip install mitproxy seems to fix my problem.

就个人而言,我发现cmd管理员身份打开然后运行 python -m pip install mitproxy 似乎可以解决我的问题。

Note:-I installed python through chocolatey

注意:-我通过安装pythonchocolatey

回答by mdev

Run cmd.exe as an administrator then type:

以管理员身份运行 cmd.exe 然后输入:

python -m pip install

回答by kichik

When all else fails, try quitting your IDE. I had many cases in which PyCharm was causing this. As soon as I quit PyCharm, I was able to finally install my packages from the command line. Alternatively, you can also install through PyCharm itself in Settings -> Project: xxx -> Project Interpreter -> +.

当所有其他方法都失败时,请尝试退出您的 IDE。我有很多 PyCharm 导致这种情况的案例。退出 PyCharm 后,我终于能够从命令行安装我的软件包。或者,您也可以在 Settings -> Project: xxx -> Project Interpreter -> 中通过 PyCharm 本身安装+

回答by Charasala

Opening command prompt As Administrator just worked for me without using Python executable. Right click on command prompt shortcut and choose "Run as Administrator". Then run the following command.

以管理员身份打开命令提示符只是为我工作,而不使用 Python 可执行文件。右键单击命令提示符快捷方式,然后选择“以管理员身份运行”。然后运行以下命令。

pip install Django

回答by Robert

One additional thing that has not been covered in previous answers and that often cause issues on Windows and stopped me from installing some package despite running as admin is that you get the same permission deniederror if there is another program that use some of the files you (or pip install) try to access. This is a really stupid "feature" of Windows that pops up many times, e.g. when trying to move some files.

以前的答案中未涵盖的另一件事通常会导致 Windows 出现问题并阻止我安装某些软件包尽管以管理员身份运行,但如果有另一个程序使用您的某些文件,您会收到相同的权限被拒绝错误(或pip install)尝试访问。这是 Windows 的一个非常愚蠢的“功能”,它会多次弹出,例如在尝试移动某些文件时。

In addition I have no clue how to figure out which program locks a particular file, so the easiest ting to do is to reboot and do the installation before starting anything, in particular before running e.g. Spyder or any other Python-based software. You can also try to close all programs, but it can be tricky to know which one actually holds a file. For a directory for example, it is enough that you have an Explorer window open at that directory.

此外,我不知道如何确定哪个程序锁定了特定文件,因此最简单的方法是在开始任何操作之前重新启动并进行安装,尤其是在运行 Spyder 或任何其他基于 Python 的软件之前。您也可以尝试关闭所有程序,但要知道哪个程序实际保存了文件可能会很棘手。例如,对于目录,在该目录中打开一个资源管理器窗口就足够了。

回答by Sharan

Open cmd with "Run as administrator" and execute the command pip install mitmproxy. It will install it.

使用“以管理员身份运行”打开 cmd 并执行命令pip install mitmproxy。它会安装它。

回答by etov

The cause in my case was having a jupyter notebook open, which was importing the relevant library; the root cause seems to be windows error due to the file being open / in use (see also @Robert's answer, and the recommendation to reboot).

就我而言,原因是打开了一个 jupyter 笔记本,它正在导入相关库;由于文件正在打开/正在使用,根本原因似乎是 Windows 错误(另请参阅@Robert 的回答以及重新启动的建议)。

So another thing to verify is that no other python processes are running.

所以要验证的另一件事是没有其他 python 进程正在运行。

For me, shutting down the notebook server solved the issue.

对我来说,关闭笔记本服务器解决了这个问题。