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

这篇博客探讨了如何在虚拟环境中更新pip。作者提到,可以像升级其他PyPI包一样使用pip来升级自身,推荐的命令因操作系统而异。在Windows上,建议使用`python -m pip install --upgrade pip`。更安全的方法是通过python模块运行pip,避免二进制文件替换自身的问题。当pip版本破损或无法自我更新时,可以使用get-pip.py脚本来安装最新版本。
摘要由CSDN通过智能技术生成

本文翻译自: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 updatepip 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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值