Python 当默认 pip 为 pip2 时,升级 pip3 的正确格式是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39129450/
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
What is the correct format to upgrade pip3 when the default pip is pip2?
提问by boardrider
I develop for both Python 2
and 3.
Thus, I have to use both pip2
and pip3.
我为两者Python 2
而开发3.
因此,我必须同时使用pip2
和pip3.
When using pip3 -
I receive this upgrade request (last two lines):
使用时,pip3 -
我收到此升级请求(最后两行):
$ pip3 install arrow
Requirement already satisfied (use --upgrade to upgrade): arrow in c:\program files (x86)\python3.5.1\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in c:\program files (x86)\python3.5.1\lib\site-packages (from arrow)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\program files (x86)\python3.5.1\lib\site-packages (from python-dateutil->arrow)
You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
My default pip
is for Python 2,
namely:
我的默认值pip
是Python 2,
:
$ python -m pip install --upgrade pip
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
However, none of the following explicitcommands succeed in upgrading the Python 3 pip:
但是,以下任何显式命令都无法成功升级Python 3 pip:
$ python -m pip3 install --upgrade pip3
/bin/python: No module named pip3
$ python -m pip install --upgrade pip3
Collecting pip3
Could not find a version that satisfies the requirement pip3 (from versions: )
No matching distribution found for pip3
$ python -m pip install --upgrade pip3.4
Collecting pip3.4
Could not find a version that satisfies the requirement pip3.4 (from versions: )
No matching distribution found for pip3.4
What is the correct command to upgrade pip3 when it is not the default pip?
当 pip3 不是默认 pip 时,升级 pip3 的正确命令是什么?
Environment:
环境:
$ python3 -V
Python 3.4.3
$ uname -a
CYGWIN_NT-6.1-WOW 2.5.2(0.297/5/3) 2016-06-23 14:27 i686 Cygwin
回答by Martijn Pieters
Just use the pip3
command you already have:
只需使用pip3
您已有的命令:
pip3 install --upgrade pip
The installed projectis called pip
, always. The pip3
command is tied to your Python 3 installation and is an alias for pip
, but the latter is shadowed by the pip
command in your Python 2 setup.
安装的项目pip
总是被称为。该pip3
命令与您的 Python 3 安装相关联,并且是 的别名pip
,但后者pip
在您的 Python 2 设置中被该命令遮蔽。
You can do it with the associated Python binary too; if it executable as python3
, then use that:
您也可以使用关联的 Python 二进制文件来完成;如果它可以作为python3
,那么使用它:
python3 -m pip install --upgrade pip
Again, the project is called pip
, and so is the module that is installed into your site-packages
directory, so stick to that name for the -m
command-line option and for the install
command.
同样,该项目名为pip
,安装到您的site-packages
目录中的模块也是如此,因此请为-m
命令行选项和命令使用该名称install
。
回答by Martin Thoma
When I searched for "how to update pip3" this came up. I had the problem described herein mind:
当我搜索“如何更新 pip3”时,出现了这个问题。我想到了这里描述的问题:
The Problem
问题
Upgrading with pip3 might make point pip
to the Python 3 version.
使用 pip3 升级可能会指向pip
Python 3 版本。
It seems as if this is not the case (any more).
似乎情况并非如此(不再如此)。
The solution
解决方案
Update the one you want to keep after the one you want to upgrade. Hence
在您要升级的那个之后更新您要保留的那个。因此
pip3 install --upgrade pip
pip2 install --upgrade pip --force-reinstall
will make sure that pip
points to pip2
.
将确保pip
指向pip2
.