【问题标题】:Cannot upgrade PIP in virtual environment无法在虚拟环境中升级 PIP
【发布时间】:2017-03-01 11:01:51
【问题描述】:

我正在尝试在虚拟环境中升级 pip。我在 ubuntu 14.04 机器上使用 venvburrito 包装器。当我尝试更新它时,我收到以下错误:

   (virtual_env) ubuntu@ip-xxxxxxx:~$ pip install pip --upgrade
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Not uninstalling pip at /home/ubuntu/.venvburrito/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg, outside environment /home/ubuntu/.virtualenvs/virtual_env
Successfully installed pip-8.1.2
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

如果我在虚拟环境中使用 sudo 尝试,我会收到以下错误:

(virtual_env) ubuntu@ip-xxxxxxx:~$ sudo pip install --upgrade pip
The directory '/home/ubuntu/.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/ubuntu/.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.
/home/ubuntu/.local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/ubuntu/.local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Requirement already up-to-date: pip in ./.local/lib/python2.7/site-packages
/home/ubuntu/.local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

当我在虚拟环境之外进行时,它会正确安装。

任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 如果您不完全了解自己在做什么,请不要使用sudo pipsudo 不保留环境变量,因此它“突破”了 venv 并可以更改系统 python 安装,从而干扰本机安装的包。特别是如果您使用 venvs,则永远不需要使用 sudo 运行 pip。
  • 谢谢@mata,会注意的
  • @SiddheshMhatre 干得好,但您需要解释它对 pip 无法自行安装的 kido 的工作原理。
  • @sam 我已经安装了 pip。我想升级它,而不是安装它。谢谢。
  • 对于我的问题投了-1票的人,很高兴知道为什么。

标签: python linux ubuntu pip


【解决方案1】:

试试这个,它对我有用。

(inside virtualenv):easy_install -U pip

(inside virtualenv):easy_install pip

【讨论】:

    【解决方案2】:

    有时这会有所帮助(我有类似的问题 pip 没有升级,第一个命令对我有用):

    python -m ensurepip
    

    python -m ensurepip --upgrade
    

    【讨论】:

    • 我不知道它是什么版本,但它肯定包含在 3.6 中
    • :) 3.6 是 python 的一个版本 :)
    【解决方案3】:

    尝试在您的 virtualenv 中按如下方式安装它:

    curl https://bootstrap.pypa.io/get-pip.py | python
    

    【讨论】:

    • 不确定,但您的问题可能与您使用 pip 升级 pip 时使用的 TLS 版本有关。见this answer
    • 一定要对脚本做哈希检查,否则这个命令是从互联网上执行任意 Python 脚本的安全风险。
    【解决方案4】:

    看到很多 pip 问题似乎都可以通过将其作为 python 模块而不是直接运行来解决:

    python -m pip install --upgrade pip

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多