Python 如何从我的虚拟环境中更新 pip 本身?

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

How do I update pip itself from inside my virtual environment?

pythonupgradevirtualenvpippackage-managers

提问by zakdances

I'm able to update pip-managed packages, but how do I update pip itself? According to pip --version, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.

我可以更新 pip 管理的软件包,但如何更新 pip 本身?根据pip --version,我目前在我的 virtualenv 中安装了 pip 1.1,我想更新到最新版本。

What's the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I've already tried pip updateand pip update pipwith no success.

那命令是什么?我需要使用分发还是有本地 pip 或 virtualenv 命令?我已经尝试过pip update,并pip update pip没有成功。

采纳答案by Cairnarvon

pipis just a PyPI packagelike any other; you could use it to upgrade itself the same way you would upgrade any package:

pip只是一个PyPI 包,就像任何其他一样;您可以像升级任何软件包一样使用它来升级自身:

pip install --upgrade pip

On Windows the recommended commandis:

在 Windows 上,推荐的命令是:

python -m pip install --upgrade pip

回答by Janusz Skonieczny

The more safe method is to run pip though a python module:

更安全的方法是通过 python 模块运行 pip

python -m pip install -U pip

On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.

在 Windows 上,尝试自我替换的二进制文件似乎存在问题,这种方法可以解决该限制。

回答by Prabhakaran KC

In my case this worked from the terminal command line in Debian Stable

在我的情况下,这在 Debian Stable 的终端命令行中起作用

python3 -m pip install --upgrade pip

回答by jmoz

In my case my pip version was broken so the update by itself would not work.

就我而言,我的 pip 版本已损坏,因此更新本身不起作用。

Fix:

使固定:

(inside virtualenv):easy_install -U pip

回答by Eamonn Kenny

I tried all of these solutions mentioned above under Debian Jessie. They don't work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option --no-cache-dir to function correctly).

我在 Debian Jessie 下尝试了上面提到的所有这些解决方案。它们不起作用,因为它只需要由 debian 包管理器编译的最新版本,即 1.5.6,相当于 6.0.x 版。某些使用 pip 作为先决条件的软件包将无法正常工作,例如 spaCy(需要选项 --no-cache-dir 才能正常运行)。

So the actual best way to solve these problems is to run get-pip.pydownloaded using wget, from the website or using curl as follows:

因此,解决这些问题的实际最佳方法是运行使用 wget、从网站或使用 curl 下载的get-pip.py,如下所示:

 wget https://bootstrap.pypa.io/get-pip.py -O ./get-pip.py
 python ./get-pip.py
 python3 ./get-pip.py

This will install the current version which at the time of writing this solution is 9.0.1 which is way beyond what Debian provides.

这将安装当前版本,在编写此解决方案时为 9.0.1,这远远超出了 Debian 提供的版本。

 $ pip --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python2.7/dist-packages (python 2.7)
 $ pip3 --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python3.4/site-packages (python 3.4)

回答by Sean

To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my "AppData\Local\Programs\Python\python35-32" directory. From there now I ran the command...

为了让它对我有用,我必须使用 Python 命令提示符(在 WIN10 上从 VS CODE)深入到 Python 目录中。就我而言,它位于我的“AppData\Local\Programs\Python\python35-32”目录中。从那里我现在运行命令......

python -m pip install --upgrade pip

This worked and I'm good to go.

这很有效,我很高兴去。

回答by Walt

I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed "cd C:\Python\Python36 to get to the right directory. Then entered the "python -m install --upgrade pip" all good!

我已经在 C:\Python\Python36 中安装了 Python,所以我转到 Windows 命令提示符并输入“cd C:\Python\Python36 到正确的目录。然后输入“python -m install --upgrade pip” all好的!

回答by MiloshB

On my lap-top with Windows 7 the right way to install latest version of pip is:

在我的装有 Windows 7 的笔记本电脑上,安装最新版本 pip 的正确方法是:

python.exe -m pip install --upgrade pip

回答by Prasad K

Very Simple. Just download pip from https://bootstrap.pypa.io/get-pip.py. Save the file in some forlder or dekstop. I saved the file in my D drive.Then from your command prompt navigate to the folder where you have downloaded pip. Then type there

很简单。只需从https://bootstrap.pypa.io/get-pip.py下载 pip 。将文件保存在某个文件夹或桌面中。我将文件保存在我的 D 驱动器中。然后从您的命令提示符导航到您下载 pip 的文件夹。然后在那里输入

python -get-pip.py

Pip installation screenshot

pip安装截图

回答by MRamzan

Open Command Prompt with Administrator Permissions, and repeat the command:

以管理员权限打开命令提示符,并重复该命令:

python -m pip install --upgrade pip