安装 pip 后立即禁用 cache/pip

安装 pip 后立即禁用 cache/pip

我正在运行 Ubuntu 15.10。我通过 aptitude 安装了 Pyhon 2.7:

sudo apt-get install python

现在我尝试使用安装pip指南。我下载了get-pip.py,然后尝试了:

sudo python get-pip.py

安装工作正常,但我收到了这些烦人的警告:

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.

因此我使用以下命令卸载了所有内容:

sudo python -m pip uninstall pip setuptools

我尝试了不带以下内容的新安装sudo

python get-pip.py

但我收到以下错误:

OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'

如何在启用缓存的情况下以正确的方式安装 pip(和wheels)?

答案1

首先,Python 2.7 已预装在当前支持的每个 Ubuntu 版本上。因此您不必先安装它。这就是我们apt-get告诉您这一点的原因python is already in the newest version

其次,除非您依赖最新版本的功能或错误修复,否则您通常应该优先选择apt从存储库打包的 Python 模块,而不是从 PyPI 获取的模块pip。存储库版本通常或多或少有些过时,但已证明与需要它们的其他任何软件包兼容。

因此,要安装pipPython 2,请运行以下命令:

sudo apt-get install python-pip

如果这个旧pip版本不能满足您的需求,您可以稍后使用以下命令获取最新版本(无需卸载旧版本!):

sudo -H pip install --upgrade pip

另一个提示:
您应该了解并使用virtualenv虚拟 Python 环境。您只能在虚拟环境中安装 Python 模块,而不会影响其他虚拟环境或系统。这是防止版本不兼容和干扰系统和其他程序所需的软件包的最安全方法。

相关内容