Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control the pip version in virtualenv

How do I control the version of pip which is used in a freshly created venv?

By default, it uses a vendored pip distribution which may be out of date or unsuitable for whatever other reason. I want to be able to create a venv with a user-specified version of pip installed initially, as opposed to creating one and then upgrading the pip installation from within the env.

like image 834
wim Avatar asked Jan 13 '14 18:01

wim


2 Answers

For me, I just upgraded pip/virtualenv/virtualenvwrapper on my machine (not inside the virtualenv). Subsequently created virtualenvs had the updated version.

deactivate pip install --upgrade pip virtualenv virtualenvwrapper mkvirtualenv ... 
like image 102
KFunk Avatar answered Sep 20 '22 13:09

KFunk


From reading the source of virtualenv, it looks like pip is installed from a source tarfile included with virtualenv. In virtualenv 1.10.1, it is pip-1.4.1.tar.gz in the site-packages/virtualenv_support directory (it gets setuptools from the same place). You could feasibly replace that archive to control the version; virtualenv.py, at least the version I have, doesn't care which version of pip is there:

    if not no_pip:         install_sdist('Pip', 'pip-*.tar.gz', py_executable, search_dirs) 

You could also pass the --no-pip option and then install the version you want from source.

In virtualenv 1.11, it looks for a wheel file (e.g. pip-*.whl) instead of a tar.gz, but other than that it acts the same way (thanks @wim for the update).

like image 26
Sam Hartsfield Avatar answered Sep 17 '22 13:09

Sam Hartsfield