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

时间:2018-06-04 16:43:59

标签: python pip virtualenv ubuntu-16.04 python-venv

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!

1 个答案:

答案 0 :(得分:2)

不尝试恢复旧线程,但这是我找到的答案,为什么使用venv-short答案-

时会发生这种情况
  

venv调用surepip.version()获取版本-获取捆绑的pip版本。

来自here:

的原始答案的积分