Maxim
Maxim

Reputation: 756

I keep getting a message to upgrade pip

Whenever I create a venv, I get a message asking me to upgrade pip:

You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

I can upgrade the Pip in that venv fine, after which it is up to date:

C:\Users\mkupfer\Python-Sandbox\sibc-python-scripts>pip --version
pip 18.0 from c:\users\mkupfer\appdata\local\programs\python\python36-32\lib\sit
e-packages\pip (python 3.6)

C:\Users\mkupfer\Python-Sandbox\sibc-python-scripts>pip3 --version
pip 18.0 from c:\users\mkupfer\appdata\local\programs\python\python36-32\lib\sit
e-packages\pip (python 3.6)

C:\Users\mkupfer\Python-Sandbox\sibc-python-scripts>pip3 install --upgrade pip
Requirement already up-to-date: pip in c:\users\mkupfer\appdata\local\programs\p
ython\python36-32\lib\site-packages (18.0)

but if I create another venv, it will have the same issue. How can I make the upgrade permanent? I tried the advice at virtualenv use upgraded system default pip, but it does not solve the problem.

Upvotes: 25

Views: 51631

Answers (8)

Tarohdit
Tarohdit

Reputation: 1

Starting with Python 3.9+, it is possible to update dependencies (including pip) when creating a virtual environment using the command

python -m venv venv --upgrade-deps

But you can also do this automatically using the standard command

python -m venv venv

To do this, you need to:

  1. Go to the Python source code, to the module "venv", for Windows 10 the default path is "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\venv"
  2. Open the __init__.py file (first make a copy just in case)
  3. At the very bottom, find the line "builder = EnvBuilder(...)"
  4. Pass True to the argument
upgrade_deps=options.upgrade_deps  # Was (passed False by default)
upgrade_deps=True  # Became
  1. Save changes

For earlier versions of Python, you will most likely have to change the "with_pip" argument (from True to False), BUT THIS IS NOT ACCURATE!

I don't know English, I used Google Translate.

Upvotes: 0

Luhn
Luhn

Reputation: 865

Situation

In my project folder there was a venv with a older version of pyhton inside (trying out stable diffusion).

Fix

Deleting this folder venv and re-executing my script worked.

Upvotes: -1

Khalil
Khalil

Reputation: 51

For me I just run:

pip install -U virtualenv

then my problem solved.

I took this answer from @James-lim Many thanks to him.

Upvotes: -2

kiran beethoju
kiran beethoju

Reputation: 158

Here is the solution to your issue.

step 1 : run this command in your shell or jupyter notebook it will securely download get-pip.py from pypa

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

step 2 : run below code

python get-pip.py

Upvotes: -1

James Lim
James Lim

Reputation: 13052

The issue seems to be that new virtual environments are using an old version of pip. Note that pip is installed from a source tarfile (or wheel) included with virtualenv, in the site-packages/virtualenv_support directory.

$ ls -l /path/to/site-packages/virtualenv_support
pip-9.1-py2.py3-none-any.whl

A quick way to workaround the problem is to make sure you upgrade pip whenever you create a new virtualenv, like so:

$ virtualenv venv
$ venv/bin/pip install -U pip

Alternatively, make sure you have the latest version of virtualenv. According to their release notes, virtualenv==16 is using pip==10.

$ pip install -U virtualenv

Finally, since virtualenv looks for pip*.whl in virtualenv_support, this will also work:

$ mv /path/to/site-packages/virtualenv_support/pip*.whl{,bak}
$ pip wheel -w /path/to/site-packages/virtualenv_support/ 'pip==18'

All new virtualenvs will use the version of pip that you installed into virtualenv_support. However, this feels hacky.

(Attempted with virtualenv==16. This results in all new virtualenvs with pip==18.)

Upvotes: 13

Krishna Kokila
Krishna Kokila

Reputation: 134

when upgrading pip would uninstall the old version, but if old version is in a different place it cant,hence ending up in two different pip versions. Check your installations on your root PYTHONPATH. Also PYTHONPATH may not be same as system path.

Upvotes: 0

wowkin2
wowkin2

Reputation: 6355

For me looks like you have multiple python environments and in one of them, there is not an upgraded pip. You have 2 options:

  • navigate to each of that folders and update each pip
  • you can remove all of them, reinstall and use virtualenv in future with correct pip
  • install some IDE (e.g. PyCharm) that can handle that automatically for you and show all issues visually

Upvotes: 6

user6767685
user6767685

Reputation:

Update pip from a bat file:

call .\venv\Scripts\activate
py -m pip install --upgrade pip
call deactivate

Or if you are in VS Code integrated Terminal

& venv/Scripts/activate.ps1
py -m pip install --upgrade pip

Upvotes: 3

Related Questions