知道如何在 Windows 盒子上更新 python PIP 吗?

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

any idea how to update python PIP on a windows box?

pythonwindowsvirtualenvpip

提问by boatcoder

pip install --upgrade pipdoesn't work because the windows FS is brain damaged and won't let you delete an open file.

pip install --upgrade pip不起作用,因为 Windows FS 大脑受损,不会让您删除打开的文件。

I've tried setting my environment to the virtualenv that I want to update and then running from a different pip, but that fails with:

我已经尝试将我的环境设置为我想要更新的 virtualenv,然后从不同的 pip 运行,但是失败了:

(jm) E:\python\jm>c:\Python26\Scripts\pip install --upgrade pip
Downloading/unpacking pip
  Running setup.py egg_info for package pip
    warning: no previously-included files matching '*.txt' found under directory 'docs\_build'
    no previously-included directories found matching 'docs\_build\_sources'
Installing collected packages: pip
  Found existing installation: pip 0.7.1
    Uninstalling pip:
      Successfully uninstalled pip
  Running setup.py install for pip
    warning: no previously-included files matching '*.txt' found under directory 'docs\_build'
    no previously-included directories found matching 'docs\_build\_sources'
    Installing pip-script.py script to c:\Python26\Scripts
    Installing pip.exe script to c:\Python26\Scripts
    Installing pip.exe.manifest script to c:\Python26\Scripts
    Installing pip-2.6-script.py script to c:\Python26\Scripts
    Installing pip-2.6.exe script to c:\Python26\Scripts
    Installing pip-2.6.exe.manifest script to c:\Python26\Scripts
Exception:
Traceback (most recent call last):
  File "c:\Python26\lib\site-packages\pip-0.7.1-py2.6.egg\pip\basecommand.py", line 120, in main
  File "c:\Python26\lib\site-packages\pip-0.7.1-py2.6.egg\pip\commands\install.py", line 165, in run
  File "c:\Python26\lib\site-packages\pip-0.7.1-py2.6.egg\pip\req.py", line 1251, in install
  File "c:\Python26\lib\site-packages\pip-0.7.1-py2.6.egg\pip\req.py", line 466, in commit_uninstall
  File "c:\Python26\lib\site-packages\pip-0.7.1-py2.6.egg\pip\req.py", line 1549, in commit
  File "c:\Python26\lib\shutil.py", line 216, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "c:\Python26\lib\shutil.py", line 216, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "c:\Python26\lib\shutil.py", line 221, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "c:\Python26\lib\shutil.py", line 219, in rmtree
    os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'c:\users\mark\appdata\local\temp\pip-gvsove-uninstall\python26\scripts\pip.exe'

Storing complete log in C:\Users\mark\AppData\Roaming\pip\pip.log

(jm) E:\python\jm>dir c:\Users\mark\AppData\Local\temp\pip-gvsove-uninstall\python26\scripts
 Volume in drive C has no label.
 Volume Serial Number is 74E4-FE9F

 Directory of c:\Users\mark\AppData\Local\temp\pip-gvsove-uninstall\python26\scripts

12/07/2010  11:32 AM    <DIR>          .
12/07/2010  11:32 AM    <DIR>          ..
05/14/2010  05:54 PM             7,168 pip.exe
               1 File(s)          7,168 bytes
               2 Dir(s)  22,824,603,648 bytes free

(jm) E:\python\jm>del c:\Users\mark\AppData\Local\temp\pip-gvsove-uninstall\python26\scripts\pip.exe

I'm hoping someone else has figured out a way around this. Its no problem on linux....

我希望其他人已经找到了解决此问题的方法。在linux上没问题....

采纳答案by Jonny Buchanan

easy_install -U pip

easy_install -U pip

:-)

:-)

回答by Mark Mikofski

[UPDATE 2015-11-15] This post is obsolete and out of date. Current best practice is according to pipis to use the following:

[更新 2015-11-15] 这篇文章已过时且过时。当前的最佳实践是根据 pip使用以下内容:

python -m pip install -U pip setuptools

It's not necessary to use easy_installfrom setuptools. The recommended procedure to update pip, from the pip-installerpage is to use get-pip.py.

没有必要使用easy_installfrom setuptools。从pip-installer页面更新 pip 的推荐程序是使用get-pip.py.

To install or upgradepip, securely download get-pip.py.

要安装或升级pip,请安全下载get-pip.py.

You can use the following in a Bash shelllike msysgit's Git Bash.

您可以在Bash shell 中使用以下内容,例如msysgit 的 Git Bash

user@machine ~$ curl -L https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | python

Use the -Loption to follow redirects. Recently GitHub changed the url for raw content, so the old raw get-pip.pyurlhas been redirectedand on the pip website the url was changed. If successful, you should see the following:

使用该-L选项跟随重定向。最近 GitHub 更改了原始内容的 url,因此旧的原始get-pip.pyurl已被重定向,并且 pip 网站上的 url 已更改。如果成功,您应该看到以下内容:

$ curl -L https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1309k  100 1309k    0     0   364k      0  0:00:03  0:00:03 --:--:--  366k
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-1.5.6-py2.py3-none-any.whl#md5=4d4fb4b69df6731c7aeaadd6300bc1f2
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Uninstalling pip:
      Successfully uninstalled pip
Successfully installed pip
Cleaning up...

You can modify this for the Windows command line, but first if you don't have libcurl, download a Windows binary from Curl. You'll want to scroll all the way to the bottom and get Günter Knauf's current official Win32 binary (currently 7.29)and unzip it. Don't worry about it being 32-bit versus 64-bit. Just make sure you get the one with all the bells and whistles (ssl, zlib, etc.). Now navigate to the folder where you downloaded curl, probably c:\Users\<you>\Downloads, open the extracted folder, probably curl-7.29.0-rtmp-ssh2-ssl-sspi-zlib-idn-static-bin-w32, and you should find curl.exe. Yay! Now in a windows shell type this after the prompt (which will have your username instead of myusername), replacing path\to\Curl\with the path to the downloaded curl.exefile.

您可以为 Windows 命令行修改它,但首先如果您没有 libcurl,请从 Curl 下载 Windows 二进制文件。您需要一直滚动到底部并获取Günter Knauf 当前的官方 Win32 二进制文件(当前为 7.29)并将其解压缩。不要担心它是 32 位还是 64 位。只要确保你得到了所有花里胡哨的东西(ssl、zlib 等)。现在导航到您下载 curl 的文件夹,可能是c:\Users\<you>\Downloads,打开解压缩的文件夹,可能是curl-7.29.0-rtmp-ssh2-ssl-sspi-zlib-idn-static-bin-w32,您应该会找到curl.exe. 好极了!现在,在 Windows shell 中,在提示后键入此内容(将使用您的用户名而不是myusername),替换path\to\Curl\为下载curl.exe文件的路径。

C:\Users\myusername> path\to\Curl\curl.exe -kL https://bootstrap.pypa.io/get-pip.py | python

You need the -koption to allow curl to access the secure GitHub pip site without certs. Also, thanks Piotr Dobrogostfor telling me about Windows pipes, |, which saves the step of saving the file.

您需要-k允许 curl 在没有证书的情况下访问安全的 GitHub pip 站点的选项。另外,感谢Piotr Dobrogost告诉我有关 Windows 管道的信息|,它省去了保存文件的步骤。

If you already have the latest version of pip you will get the following message:

如果您已经拥有最新版本的 pip,您将收到以下消息:

$ curl https://bootstrap.pypa.io/get-pip.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1309k  100 1309k    0     0   369k      0  0:00:03  0:00:03 --:--:--  371k
Requirement already up-to-date: pip in c:\python27\lib\site-packages
Cleaning up...

Also works just fine in virtualenvs.

在 virtualenvs 中也能正常工作。

回答by Christian Long

Run pip as a script, using python as the main executable.

将 pip 作为脚本运行,使用 python 作为主要可执行文件。

python -m pip install -U pip

回答by OM Bharatiya

Try:
Right Click Anaconda Prompt (Run as Admin)

尝试:
右键单击 Anaconda Prompt(以管理员身份运行)

>> conda update pip

(If you are using Anaconda. PS: It worked for me)

(如果您使用的是 Anaconda。PS:它对我有用)

回答by maheshmnj

pip install pip --upgrade

pip install pip --upgrade

enter image description hereworked for me

在此处输入图片说明为我工作

Note: Make sure you are running command Prompt in administrator mode

注意:确保您在管理员模式下运行命令提示符

回答by user2255224

Hey i Just able to Upgrade PIP on Python 36 with Following Command in CMD

嘿,我只能使用 CMD 中的以下命令在 Python 36 上升级 PIP

python -m pip install --upgrade pip

python -m pip install --upgrade pip

CMD : Upgrading PIP in Python 36

CMD:在 Python 36 中升级 PIP