简体   繁体   English

pip 在 Windows 上安装访问被拒绝

[英]pip install access denied on Windows

I am trying to run pip install mitmproxy on Windows, but I keep getting access denied, even with cmd and PowerShell using the Run as Administrator option. I am trying to run pip install mitmproxy on Windows, but I keep getting access denied, even with cmd and PowerShell using the Run as Administrator option.

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?我怎样才能使这项工作?

For Windows, in Command Prompt (Admin) try to run pip install using the Python executable:对于 Windows,在命令提示符(管理员)中尝试使用 Python 可执行文件运行pip install

python -m pip install mitmproxy

This should work, at least it worked for me for other package installation.这应该有效,至少它对我的其他软件包安装有效。

Change your Python installation folder's security permissions by:通过以下方式更改 Python 安装文件夹的安全权限:

  1. Open a Python shell打开 Python 外壳
  2. Go to task manager进入任务管理器
  3. Find the python process找到python进程
  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保存您的更改

If you open cmd as admin;如果您以管理员身份打开cmd then you can do the following:那么您可以执行以下操作:

If Python is set in your PATH , then:如果 Python 在您的PATH中设置,则:

python -m pip install mitmproxy

Personally, I found that by opening cmd as admin then run python -m pip install mitproxy seems to fix my problem.就个人而言,我发现通过以管理员身份打开cmd然后运行python -m pip install mitproxy似乎可以解决我的问题。

Note:- I installed python through chocolatey注意:-我通过chocolatey安装了 python

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 denied error if there is another program that use some of the files you (or pip install ) try to access.以前的答案中未涵盖的另一件事,通常会导致 Windows 上出现问题,并阻止我安装某些软件包,尽管以管理员身份运行是,如果有另一个程序使用您的某些文件,您会收到相同的权限被拒绝错误(或pip install )尝试访问。 This is a really stupid "feature" of Windows that pops up many times, eg when trying to move some files.这是 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 eg Spyder or any other Python-based software.此外,我不知道如何确定哪个程序锁定了特定文件,因此最简单的方法是在开始任何操作之前重新启动并进行安装,特别是在运行例如 Spyder 或任何其他基于 Python 的软件之前。 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.例如,对于一个目录,在该目录打开一个资源管理器窗口就足够了。

As, i am installing through anaconda Prompt .In my case, it didn't even work with python -m pip install Then, i add this因为,我正在通过 anaconda Prompt 安装。就我而言,它甚至无法与python -m pip install一起使用然后,我添加了这个

python -m pip install <package_name> --user

It works for me.这个对我有用。

Like: python -m pip install mitmproxy --user喜欢: python -m pip install mitmproxy --user

Another you should try that run the Command Prompt as Run as Administrator and then try pip install.另一个您应该尝试以管理员身份运行命令提示符,然后尝试 pip install。 It should work either.它也应该工作。

Open cmd with "Run as administrator" and execute the command pip install mitmproxy .使用“以管理员身份运行”打开 cmd 并执行命令pip install mitmproxy It will install it.它将安装它。

The cause in my case was having a jupyter notebook open, which was importing the relevant library;我的原因是打开了一个 jupyter notebook,它正在导入相关的库; 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).根本原因似乎是由于文件打开/正在使用而导致的 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.对我来说,关闭笔记本服务器解决了这个问题。

Try to give permission to full control the python folder.尝试授予完全控制 python 文件夹的权限。

Find the python root directory-->right button click-->properties-->security-->edit-->give users Full Control-->yes and wait the process finished.找到python根目录-->右键单击-->properties-->security-->edit-->give users Full Control-->yes,然后等待过程完成。

It works for me.这个对我有用。

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

Opening command prompt As Administrator just worked for me without using Python executable.以管理员身份打开命令提示符只是为我工作,而不使用 Python 可执行文件。 Right click on command prompt shortcut and choose "Run as Administrator".右键单击命令提示符快捷方式,然后选择“以管理员身份运行”。 Then run the following command.然后运行以下命令。

pip install Django

When all else fails, try quitting your IDE.当所有其他方法都失败时,请尝试退出您的 IDE。 I had many cases in which PyCharm was causing this.我有很多案例是 PyCharm 造成这种情况的。 As soon as I quit PyCharm, I was able to finally install my packages from the command line.一旦我退出 PyCharm,我终于可以从命令行安装我的包了。 Alternatively, you can also install through PyCharm itself in Settings -> Project: xxx -> Project Interpreter -> + .或者,您也可以通过 PyCharm 本身在 Settings -> Project: xxx -> Project Interpreter -> +中安装。

  1. Open Command Prompt as Administrator.以管理员身份打开命令提示符。

  2. To Install any Python Package use this command including --user .要安装任何 Python 包,请使用此命令,包括--user

pip install --ignore-installed --upgrade --user <packagename>

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

python -m pip install

I met a similar problem.But the error report is about我遇到了类似的问题。但是错误报告是关于

[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)

First I tried this https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035 ,but seems it couldn't solve my problems,and still repeat the same issue.首先我尝试了这个https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035 ,但似乎它无法解决我的问题,并且仍然重复同样的问题。

And Second if you are working on a business computer,generally it may exist a web content filter(but I can access https://pypi.python.org through browser directly).And solve this issue by adding a proxy server.其次,如果您使用的是商务计算机,通常可能存在Web内容过滤器(但我可以通过浏览器直接访问https://pypi.python.org )。并通过添加代理服务器来解决此问题。

For windows,open the Internet properties through IE or Chrome or whatsoever ,then set valid proxy address and port ,and this way solve my problems对于windows,通过IE或Chrome或任何方式打开Internet properties ,然后设置有效的代理地址和端口,这样就解决了我的问题

Or just adding the option pip --proxy [proxy-address]:port install mitmproxy .But you always need to add this option while installing by pypi或者只是添加选项pip --proxy [proxy-address]:port install mitmproxy 。但是你总是需要在通过 pypi 安装时添加这个选项

The above two solution is alternative for you demand.以上两种解决方案是您需求的替代方案。

In my case, it didn't even work with python -m pip install就我而言,它甚至不适用于python -m pip install

What I have done is, from a cmd as administrator:我所做的是,从 cmd 作为管理员:

PsExec.exe -i -s -d cmd.exe

In order to spawn a SYSTEM cmd, then pip install mitmproxy为了产生一个 SYSTEM cmd,然后pip install mitmproxy

;) ;)

Running cmd as administrator solved for me.以管理员身份运行 cmd 为我解决了问题。 You can also try --user.你也可以试试 --user。 If you do not want to repeat the steps you need to give full access to anaconda folder.如果您不想重复这些步骤,则需要授予对 anaconda 文件夹的完全访问权限。

Had the same problem when installing pycaret .安装pycaret时遇到了同样的问题。

I've solved in two different ways (that I'll list below).我已经以两种不同的方式解决了(我将在下面列出)。


Option 1选项1

Upgraded pip with升级点与

python -m pip install --user --upgrade pip

Then然后

pip install --user pycaret[full]

Found a relevant discussion on the error here .此处找到有关该错误的相关讨论。


Option 2选项 2

Assuming one is using Anaconda, open Anaconda prompt, for the environment one is working with, as admin假设一个正在使用 Anaconda,打开 Anaconda 提示符,对于正在使用的环境,以管理员身份

在此处输入图像描述

And run并运行

pip install --user pycaret[full]

or或者

pip install pycaret[full]

In my case, Windows Defender is blocking the process and every time I run a pip command it will show pop up of security threat.就我而言,Windows Defender 正在阻止该进程,每次我运行 pip 命令时,它都会弹出安全威胁。 What I do is exclude the python folder.我所做的是排除 python 文件夹。 Below are the steps:以下是步骤:

  • Click the Windows icon, search "Windows Security" app, and open it单击 Windows 图标,搜索“Windows 安全”应用,然后打开它
  • Choose Virus & threat protection on the left menu在左侧菜单中选择病毒和威胁防护
  • Scroll down to Virus & threat protection settings向下滚动到病毒和威胁防护设置
  • Click Manage settings点击管理设置
  • Scroll down to Exclusions向下滚动到排除项
  • Click Add or remove exclusions单击添加或删除排除项
  • Click Add an exclusion, and choose Folder单击添加排除项,然后选择文件夹
  • Navigate to this path C:\Users{Your_User}\AppData\Local\Programs\Python导航到此路径 C:\Users{Your_User}\AppData\Local\Programs\Python
  • Select folder选择文件夹
  • Relaunch your Command prompt重新启动命令提示符

Sometimes you just need to make sure you do not have any python environments running.有时您只需要确保没有运行任何 python 环境。

I also work in secure environment, Hence for install module I use this code:-我也在安全环境中工作,因此对于安装模块,我使用以下代码:-

pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org

in last add your library name, such as:在最后添加您的库名称,例如:

pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org numpy 

Just close all the python files opened.只需关闭所有打开的 python 文件。 And try to run as administrator.并尝试以管理员身份运行。 It will work.它会起作用的。

eg例如

pip install mitmproxy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM