Why does Python's pip reset to version 10.0.1 in every new virtual environment?

tl;dr: Why is pip’s version reset to 10.0.1 every time I create a new virtual environment and not automatically cloned from my global 18.0 installation?

Every time I create a new virtual environment I’m told that my pip is outdated. I run

$ pip install --upgrade pip

And get the following output:

Collecting pip
  Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0

Running pip -V outside of a virtual environment returns

pip 18.0 from /usr/lib/python3.7/site-packages/pip (python 3.7)

So the outdated version is only created when I create a new virtual environment.

Is this a feature of python’s virtual environment module?

For the record, the command I run to create a new virtual environment is:

$ python -m venv <venv>

I installed it by running

$ pacman -S python python-pip

I am running it in Arch and the output of python -V is Python 3.7.0.

Asked By: mas

||

pip is not reset when you create a new virtual environment. When you create a new virtual environment, venv performs a new installation of pip and setuptools in this environment. Where does the pip version come from? When you run python -m venv, the installation of pip is a responsibility of the module ensurepip which bootstraps a new pip installation. You can check what pip version is bundled with Python 3.7:

$ python3 -c "import ensurepip; print(ensurepip.version())"
10.0.1

This is nothing you can update or modify yourself; the module is part of the standard library. When Python 3.7 was released, the latest pip was of version 10.0.1, so it was bundled (related issue). Version 18 was released later. Next time, it will be probably updated in the next Python release (3.7.1).

Alternative: using virtualenv

If you want the latest pip to be installed in a fresh virtual environment, you can switch to virtualenv:

$ pip install --user virtualenv

or install system wide using pacman:

$ pacman -S python-virtualenv

virtualenv is updated more often than Python, so the latest version installs the latest packages. Usage example:

$ virtualenv myenv --python=python3 --quiet
$ source myenv/bin/activate
(myenv) $ pip --version
pip 18.0 from /Users/hoefling/.virtualenvs/myenv/lib/python3.7/site-packages/pip (python 3.7)
Answered By: hoefling