Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tox uses wrong version of pip when multiple versions of python are installed

I have a build box which supports python 2.4, 2.6 and 2.7. This leads to installing various versions of pips as required in their own python installations. I'm using tox to run tests through setup.py.

Whenever I run a {python2.7_installation_dir}/bin/python setup.py test, this results in a .tox directory. Inside .tox directory I run

py27/bin/pip --version 
pip 1.4.1 from {my_package}/.tox/py27/lib/python2.7/site-packages (python 2.7)


[buildbot@BUILD-SERV-01 .tox]# python2.7 
Python 2.7.6 (default, Nov 20 2013, 15:33:09) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> pip.__version__
'1.5.2'

So the version of pip inside .tox directory is 1.4.1 where as pip installed for python interpreter that I'm using to execute the setup.py test is 1.5.2. This leads to errors when running tests as it uses pip to install the directories and some of them come from external sources and in 1.5.2 we need to set explicitly --allow-external --allow-unverified flag for one of the module which doesn't exist in 1.4.1, which results in an error each time i invoke tests through tox.

There is only one python2.7 installation and it is installed from source. But I think it was running pip 1.4.1, but now been upgraded to use 1.5.2. How tox can use the old version? Is there any .pth file or something that could have been left behind which needs clearing up?

I could drop tox and run pytests directly but I'd prefer to run them via tox.
Please let me know if you want to see the logs, I can update the question with the log.

like image 341
opensourcegeek Avatar asked Feb 12 '14 14:02

opensourcegeek


1 Answers

tox creates a virtualenv in .tox/py27, .tox/py35 etc depending on the python versions you test with (i.e. based on you envlist in tox.ini or the argument to the -e option). tox then installs pip into this virtualenv, and your packages, and all packages your package is dependent upon.

On further runs, to save time, the virtualenv is reused and only your package is reinstalled (and possible dependencies updated). Your pip will stay at the original version unless you do:

./tox/py27/bin/pip install -U pip

or reinitialises the complete virtualenv with:

tox -r -e py27

(or tox -r for all .tox virtualenvs for all python versions in your envlist).

If you further want to analyse how tox does the setup, first call:

tox -r -e py27 -vv

from the output you can see the recreate step:

py27 recreate: /src/site-packages/your/package/.tox/py27
  removing /src/site-packages/your/package/.tox/py27
setting PATH=/src/site-packages/your/package/.tox/py27/bin:/opt/python/2.7/bin:........
  /src/site-packages/your/package/.tox$ python -m virtualenv --python /opt/python/2.7.13rc1/bin/python py27 >/src/site-packages/your/package/.tox/py27/log/py27-0.log

Now you go to the .tox directory and redo the virtualenv creation verbose:

cd .tox; rm -rf py27
python -m virtualenv --python /opt/python/2.7/13rc1/bin/python py27

From that log you'll see that it uses the latest (cached) version of pip. As your normal install gets you the latest pip version, there should be no need to clean/update pip's cache.

like image 174
Anthon Avatar answered Oct 21 '22 15:10

Anthon