我正在运行 Ubuntu 15.10。我通过 aptitude 安装了 Pyhon 2.7:
sudo apt-get install python
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用本指南安装 pip 。我下载了get-pip.py,然后我尝试:
sudo python get-pip.py
Run Code Online (Sandbox Code Playgroud)
安装工作正常,但我收到了这些烦人的警告:
The directory '/home/administrator/.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/administrator/.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.
Run Code Online (Sandbox Code Playgroud)
所以我通过以下命令卸载了所有内容:
sudo python -m pip uninstall pip setuptools
Run Code Online (Sandbox Code Playgroud)
我尝试了一个没有的新安装sudo:
python get-pip.py
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'
Run Code Online (Sandbox Code Playgroud)
如何在启用缓存的情况下以正确的方式安装 pip(和轮子)?
首先,Python 2.7 已经预先安装在每个当前支持的 Ubuntu 版本上。所以你不必先安装它。这就是为什么apt-get告诉你python is already in the newest version。
其次,您通常应该更喜欢apt从存储库打包的 Python 模块,而不是pip从 PyPI获得的模块,除非您依赖最新版本的功能或错误修复。存储库版本通常或多或少已经过时,但已证明与需要它们的任何其他软件包兼容。
因此,要pip为 Python 2安装,请运行以下命令:
sudo apt-get install python-pip
Run Code Online (Sandbox Code Playgroud)
如果这个旧pip版本不能满足您的需求,您可以稍后使用以下命令简单地获取最新版本(无需卸载旧版本!):
sudo -H pip install --upgrade pip
Run Code Online (Sandbox Code Playgroud)
给您的另一个提示:
您应该了解并使用virtualenv虚拟 Python 环境。您只能在 viertualenv 中安装 Python 模块,而不会影响其他 virtualenv 或系统。这是防止版本不兼容和混淆系统和其他程序所需的包的最安全方法。
| 归档时间: |
|
| 查看次数: |
11810 次 |
| 最近记录: |