简体   繁体   中英

Tox installs the wrong version of pip to it's virtual env

I am using tox to manage some testing environments. I have a dependency (backports.ssl-match-hostname) that I cannot download using the latest version of pip, so I need to revert back to pip 8.0.3 to allow the install to work.

I have included the 8.0.3 version of pip inside my tox.ini file for dependencies.

deps=
    pip==8.0.3

However, when I run

source .tox/py27/bin/activate

and enter the virtual testing environment, and then run

pip --version

I end up with

8.1.2

However, outside of my tox environment, when I run the same command, I get

8.0.3

Is there anything special that tox does when grabbing pip? Why am I not able to specify the version of pip that I want to use as a dependency?

EDIT : to add to this, it seems as though I am able to grab the dependency pip==8.0.3, but for the other dependencies, they are still running from the command launched with pip==8.1.2

So, I need to be able to grab pip==8.0.3 first, and then once installed, grab everything else. Still unsure why tox is starting with pip==8.1.2

This was apparently the result of the "virtualenvs" python package containing a pre-selected group of python packages that it refers to, one of which was the latest and greatest pip.

I don't know if this is the preferred way of doing this, but I found success by running

pip uninstall virtualenv

And then reinstalling with the version that worked

pip install virtualenv==15.0.1

With the "correct" version of virtualenv in place, I was able to run my tox command

source .tox/py27/bin/activate

and see the desired version of pip

pip --version
pip 8.0.3

A workaround for this is here: https://github.com/pypa/pip/issues/3666

Although to make it work I had to write "pip install pip==8.1.1" in my script. So to recap:

Add a pip.sh script to your project:

#!/bin/bash
pip install pip==8.1.1
pip install "$@"

Add to your tox.ini:

install_command = {toxinidir}/pip.sh {opts} {packages}

I've recently hit this problem. I've had it for a while but it just didn't register because I had such occasional failures with Python 2/3 code. Another way that this can happen is, if like me, you change the virtualenv between different Python versions and don't clean up.

Check /bin or /Scripts to see whether python2 points to python . If the virtualenv is Python 3 then this will mean that python2 actually calls Python 3. Vice versa, of course, if you the virtualenv is Python 2 and you want to test Python 3 code.

新版本的virtualenv可以下载最新的pipsetuptoolswheel - 你可以在使用tox-virtualenv-no-download软件包运行tox时禁用此行为请参阅: https//github.com/asottile/tox -virtualenv-没有下载#观望为什么

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM