本文翻译自:How do I update pip itself from inside my virtual environment?
I'm able to update pip-managed packages, but how do I update pip itself? 我能够更新pip托管包,但是如何更新pip本身? According to pip --version
, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version. 根据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? 我是否需要使用分发或是否有本机pip或virtualenv命令? I've already tried pip update
and pip update pip
with no success. 我已经尝试了pip update
和pip update pip
没有成功。
#1楼
参考:https://stackoom.com/question/11rnd/如何从我的虚拟环境中更新pip本身
#2楼
pip
is just a PyPI package like any other; pip
就像其他任何一个PyPI包一样; you could use it to upgrade itself the same way you would upgrade any package: 您可以像升级任何包一样使用它来升级自己:
pip install --upgrade pip
On Windows the recommended command is: 在Windows上, 推荐的命令是:
python -m pip install --upgrade pip
#3楼
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上,似乎有二进制文件试图替换自己的问题,这种方法可以解决这个限制。
#4楼
在我的例子中,这是从Debian Stable的终端命令行开始的
python3 -m pip install --upgrade pip
#5楼
In my case my pip version was broken so the update by itself would not work. 在我的情况下,我的pip版本被破坏,因此更新本身不起作用。
Fix: 固定:
(inside virtualenv):easy_install -U pip
#6楼
I tried all of these solutions mentioned above under Debian Jessie. 我在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. 它们不起作用,因为它只需要由debian软件包管理器编译的最新版本,即1.5.6,相当于版本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). 一些使用pip作为先决条件的软件包将无法用作结果,例如spaCy(需要选项--no-cache-dir才能正常运行)。
So the actual best way to solve these problems is to run get-pip.py downloaded 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)