Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my venv using a different pip version than I have installed

Tags:

python

pip

I'm setting up virtual env. I was getting warnings about an outdated pip (19.2) so I updated pip on my (macos) system globally, sudo -H python3 -m pip install --upgrade pip. It seems to have worked, but when I make a new venv, I'm still getting the old pip version.

% pip --version           
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% python3 -m pip --version
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% rm -rf .venv # make sure
% python3 -m venv .venv   
% . .venv/bin/activate    
(.venv)     % python3 -m pip --version
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)
(.venv)     % pip --version           
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)

Where is the older version coming from?

like image 604
Marvin Avatar asked May 02 '20 02:05

Marvin


People also ask

What version of Python does venv use?

virtualenv supports older Python versions and needs to be installed using the pip command. In contrast, venv is only used with Python 3.3 or higher and is included in the Python standard library, requiring no installation.

Does pip install to venv?

Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

Why can’t I install any additional packages with pip install venv?

If you are in a production environment, you run pip install -r requirements.txt, and the extra packages in ‘requirements-dev.txt’ won’t be installed. There is an alternative to venv called pipenv, you can learn about it in this article: Virtual Environments in Python with Pipenv

What version of python do you use to create Venvs?

Python 3.8.2 is vendoring pip 19.2.3 and setuptools 41.2.0, matching what you've seen. To create venvs directly with the latest pip version, rather than creating them with an older pip and then upgrading the pip version, refer to this answer:

How do I install the latest version of Pip?

The Python installers for Windows include pip. You can make sure that pip is up-to-date by running: py -m pip install --upgrade pip py -m pip --version Afterwards, you should have the latest version of pip: pip 21.1.3 from c:\python39\lib\site-packages (Python 3.9.4) Installing virtualenv¶ Note

Why pipenv over venv for Python projects?

By default, every Python project on your system will use these same directories to store and retrieve site packages (third party libraries).


1 Answers

Pip is installed anew in any freshly created venv. The venv's default pip version is associated with the Python version, and is completely independent from whatever pip version you may have installed on the system. The older version comes from a wheel file bundled with the stdlib ensurepip module. This allows users to create a venv even with no internet connection available, as the venv docs mention:

Unless the --without-pip option is given, ensurepip will be invoked to bootstrap pip into the virtual environment

You can check the bundled pip version with ensurepip.version:

>>> import ensurepip
>>> ensurepip.version()
'19.2.3'

Python 3.8.2 is vendoring pip 19.2.3 and setuptools 41.2.0, matching what you've seen.

To create venvs directly with the latest pip version, rather than creating them with an older pip and then upgrading the pip version, refer to this answer:

How to get “python -m venv” to directly install latest pip version

like image 130
wim Avatar answered Sep 17 '22 12:09

wim