将pip升级到pip3的问题

时间:2018-02-20 13:35:33

标签: python linux installation pip

我试图将pip升级到pip3,我发现了2个问题。

1)pip chache所在的行为,我的root用户无法访问我的useradmin。

2)Linux默认为python2.7,我安装了python2.7和python3.5。但出于某种原因,O.S。我认为我只安装了python2.7所以此时PIP是最新的,我怎么能默认设置python3.5(或设置两者)来实现安装pip3?

xxxx@yyyy:~$ pip3 install virtualenv
Collecting virtualenv
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 579kB/s 
Installing collected packages: virtualenv
Successfully installed virtualenv-15.0.3
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
xxxx@yyyyy:~$ sudo pip install --upgrade pip
[sudo] password for xxxx: 
The directory '/home/xxxx/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/xxxx/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist-packages
enter code here

2 个答案:

答案 0 :(得分:2)

pip3是来自pip的单独命令。你想要做的是:

pip3 install --upgrade --user pip

这将在您的主文件夹中安装更新的pip3;在我的机器上它是~/.local/lib/python3.5/site-packages。如果不使用sudo并全局安装,则可以避免弄乱程序包管理器提供的版本。因此--user选项。

来自pip3的警告的措辞是因为pip总是假设它是唯一安装的版本,这在Linux机箱上很少出现。

此外,您无法为python2安装安装pip3。它真的只是pthon for python3。

答案 1 :(得分:0)

你可以简单地做“sudo python3 -m pip install” 而不是设置可能导致一些问题的默认python。