Python3 pip3无法安装请求

时间:2017-05-15 09:05:54

标签: python linux ubuntu pip python-requests

在我的Ubuntu 16.04桌面上安装了python2.7.12和python3.6.1。

seept@seept:~$ python --version
Python 2.7.12
seept@seept:~$ python3 --version
Python 3.6.1

我还安装了pip和pip3。是pip用于python2而pip3用于python3吗?

那么为什么两个版本的pip都会让我看到这个:

seept@seept:~$ pip --version
pip 9.0.1 from /home/seept/.local/lib/python3.5/site-packages (python 3.5)
seept@seept:~$ pip3 --version
pip 9.0.1 from /home/seept/.local/lib/python3.5/site-packages (python 3.5)

为何选择Python 3.5?

seept@seept:~$ which python
/usr/bin/python

seept@seept:~$ which python3
/usr/local/bin/python3

seept@seept:~$ which pip
/home/seept/.local/bin/pip

seept@seept:~$ which pip3
/home/seept/.local/bin/pip3

所以我真正的问题是我需要模块'请求'对于python3项目。

当我跑步时:

seept@seept:~$ sudo pip3 install requests

这是输出:

The directory '/home/seept/.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/seept/.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 satisfied: requests in ./.local/lib/python3.5/site-packages**

顺便说一句,我总是收到这条消息:

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.

所以这个输出说我正在使用pip verison 8.1.1,但是当我运行pip --version时它告诉我我正在运行9.0.1版本。

对我来说,看起来我已经搞砸了,应该重新安装所有?

1 个答案:

答案 0 :(得分:0)

您应该使用virtualenv运行您的项目。它可以保护您的项目目录,并避免与其他版本冲突。

转到您的项目目录,然后使用以下命令安装第一个virtualenv:

pip install virtualenv

在安装软件包之前,请运行此命令以激活virtualenv:

source venv/bin/activate

现在您的目录是安全的,您可以在此处安装您的软件包,以便在另一个目录中保持安全和唯一。

希望你理解我的观念。

感谢。