1

I am trying to upgrade pip in a virtual environment. I am using the venvburrito wrapper, in an ubuntu 14.04 machine. When I try to update it I get the following error:

   (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.

If I try it with sudo, inside the virtual environment, I get the following error:

(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

When I do it outside the virtual environment, it installs correctly.

Any help will be much appreciated.

Thanks

Escachator
  • 1,742
  • 1
  • 16
  • 32
  • 1
    Don't use `sudo pip` if you don't exactly know what you are doing! `sudo` does not preserve environment variables, so it "breaks out" of the venv and can change the system python installation interfering with native installed packages. Specially if you're working with venvs you should never need to run pip with sudo. – mata Mar 01 '17 at 11:23
  • thanks @mata, will take note of that – Escachator Mar 01 '17 at 11:24
  • @SiddheshMhatre nice work but you need to explain how its work for kido that pip cannot install itself. –  Mar 01 '17 at 11:41
  • @sam I have pip already installed. I want to upgrade it, not install it. Thanks. – Escachator Mar 01 '17 at 14:31
  • 1
    For the one who voted -1 to my question, would be great to know why. – Escachator Mar 02 '17 at 11:21

4 Answers4

4

Try this one, it worked for me.

(inside virtualenv):easy_install -U pip

or

(inside virtualenv):easy_install pip
Vikash Kumar
  • 348
  • 1
  • 9
1

sometimes this helps(I had similar issue pip not upgrading and 1st command worked for me):

python -m ensurepip

or

python -m ensurepip --upgrade
Drako
  • 773
  • 10
  • 22
0

Try installing it as follows, within your virtualenv:

curl https://bootstrap.pypa.io/get-pip.py | python
Anupam
  • 14,950
  • 19
  • 67
  • 94
  • Not sure but your issue could be related to the TLS version being used when you use `pip` to upgrade `pip`. See [this answer](https://stackoverflow.com/a/49748494/1526703) – Anupam Apr 15 '18 at 08:32
  • Be sure to do a hash check on the script, or else this command is a security risk by executing an arbitrary Python script from the internet. – cowlinator Feb 04 '22 at 22:50
0

Seen a lot of problems with pip that all seem to be fixed by running it as a python module instead of directly:

python -m pip install --upgrade pip

wooden
  • 11
  • 4