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.

  • Never ran pip install --upgrade pip outside of a virtual environment. I ran one really long command early on in my current set up (August 1, 20018) that included sudo pacman -S ... python ipython python-pip ... – malan Aug 24 '18 at 16:38
  • Also: I have seen this problem on every arch system I've installed: several times in the last 6 months. – malan Aug 24 '18 at 16:40
  • python-pip is at 18.0-1 in Arch; your venv is broken in some way. – jasonwryan Aug 24 '18 at 18:56
  • @jaysonwryan: read my update: my python-pip for the system is 18.0-1. It's whenever I create a new virtual environment the venv's pip is 10. – malan Aug 24 '18 at 20:32
  • Yes, that is why I am saying that it is the venv that is broken; not Arch. – jasonwryan Aug 24 '18 at 20:36

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())"

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)
  • Other than being up to date, is there any other benefit to python-virtualenv? I am not overly bothered by the fact that I have to update pip in a new venv, I was just incredibly curious about why. – malan Aug 25 '18 at 19:34
  • 1
    To me, this is more a matter of personal preferences. venv is more or less the virtualenv, but without all the hacks virtualenv has to use due to not being a part of the stdlib. So you can say venv is more stable and reliable. – hoefling Aug 25 '18 at 22:14
  • 1
    However, virtualenv is an old and mature project, being available for both Python 2 and 3 and having many handy tools evolved around it in all the years. To name a few: virtualenvwrapper which simplifies organizing and handling of local virtual environments. This is the tool I use in daily work most of the time. pipenv, sort of a pendant of npm/yarn in the Python world. tox, a must-have tool for tests automation in different environments/ for different Python versions. All of them require virtualenv as the core dependency in the first place. – hoefling Aug 25 '18 at 22:27
  • 1
    Reagrding: "Next time, it will be probably updated in the next Python release (3.7.1)." It hasn't been updated. – Marcus Nov 1 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.