![](/img/trans.png)
[英]Why I can't install any package using pip and pip3 but python3 -m?
[英]Python3 pip3 can't install 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版本8.1.1,但是当我运行pip --version
它表明我正在运行9.0.1版本。
对我来说,我好像已经搞砸了,应该重新安装所有程序吗?
您应该使用virtualenv运行项目。 它可以确保您的项目目录安全,并避免与其他版本的冲突。
转到您的项目目录,然后使用以下命令安装第一个virtualenv:
pip install virtualenv
在安装软件包之前,请运行以下命令激活virtualenv:
source venv/bin/activate
现在您的目录是安全的,您可以在此处安装软件包,以保持安全和与其他目录不同。
希望你理解我的概念。
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.