Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

venv vs virtualenv - Why does venv not use the current pip and setuptools? [duplicate]

When using python -m venv env to create a new virtual environment in python3.X, env does not contain the pip and setuptools versions I would expect. Instead, it contains quite "old" versions: pip (8.1.1) and setuptools (20.7.0) as of June 2018.

On the other hand, when using virtualenv env (installed via pip install virtualenv), the pip and setuptools packages are the latest available, i.e. pip (10.0.1) and setuptools (39.2.0) as of June 2018.

The way I understood it, venv is the preferred module to build virtual environments because it does not need to create a new instance of the Python interpreter and uses the present modules (symlinks in Linux, copies in Windows) without needing to install anything ( https://www.reddit.com/r/learnpython/comments/4hsudz/pyvenv_vs_virtualenv/d2s2cda ).

How come that venv's pip version doesn't match the current system's one? And that the behaviour using virtualenv is so different?

PS:

A short term solution is to use pip install --upgrade pip in the env. But that doesn't seem right to me. Minimum viable solution:

$ python --version
Python 3.6.5
$ pip --version
pip 10.0.1 from /home/lionel/.local/lib/python3.6/site-packages/pip (python 3.6)
$ python -m venv env
$ . env/bin/activate
(env) $ # Here I am at version 8.1.1 of pip. Why did venv create its own pip,
(env) $ # instead of linking to the system one? As seen before, that was 10.0.1.
(env) $ pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
Successfully installed pip-10.0.1
(env) $ pip list
Package       Version
------------- -------
pip           10.0.1 
pkg-resources 0.0.0  
setuptools    20.7.0 
(env) $ # Solved, now pip is the one I was expecting!
like image 717
Lionel Trebuchon Avatar asked Jun 04 '18 16:06

Lionel Trebuchon


1 Answers

Not trying to revive an old thread, but here is the answer i found to why this happens when using venv- short answer-

venv calls ensurepip.version() to get the version- that gets the bundled pip version.

Credits to original answer from here:

like image 98
A.J Avatar answered Sep 21 '22 10:09

A.J