[Tox Support] Tox Wants to Recreate 2.7 Environment When Active, but Not 3.6

Dan Lidral-Porter dlidral-porter at cylance.com
Mon Jan 14 23:58:18 UTC 2019


Hey Everybody,

I’ve run into a strange situation where Tox wants to recreate a Python 2.7 virtual environment whenever Tox is run with that environment active, using that environment’s own Python interpreter (which fails for obvious reasons). Curiously, this is not the case for the Python 3.6 environment when it is active, even though both of the environments’ Python interpreters have different MD5 sums than the system’s corresponding interpreter.

I’ve attached a minimal tox.ini file that reproduces my behavior. I am on OS X 10.13.6 with Python 2.7.15 and Python 3.6.5 installed with Homebrew. After the environments have been set up, I can then activate the Python 3.6 environment (named 'env') and re-run tox with no problems. Tox reuses the existing virtual environment so my command is quickly and successfully rerun. But if I activate the Python 2.7 environment 'py27-env', tox tries to recreate py27-env using that environment's own interpreter, which — apart from being unnecessary — fails:

```
$ tox -ve py27-env
using tox.ini: /Users/Daniel/src/scratch/tox-and-venvs/tox.ini
using tox-3.7.0 from /usr/local/lib/python3.6/site-packages/tox/__init__.py
py27-env cannot reuse: attr base_resolved_python_md5 'bcfb5e550c2f501eb867a8aad7422ab7'!='c542cd220de26a93bf578d050a8926ec'
py27-env recreate: /Users/Daniel/src/scratch/tox-and-venvs/py27-env
  /Users/Daniel/src/scratch/tox-and-venvs$ /usr/local/opt/python/bin/python3.6 -m virtualenv --python /Users/Daniel/src/scratch/tox-and-venvs/py27-env/bin/python2.7 py27-env >/Users/Daniel/src/scratch/tox-and-venvs/py27-env/log/py27-env-0.log
ERROR: invocation failed (exit code 3), logfile: /Users/Daniel/src/scratch/tox-and-venvs/py27-env/log/py27-env-0.log
ERROR: actionid: py27-env
msg: getenv
cmdargs: '/usr/local/opt/python/bin/python3.6 -m virtualenv --python /Users/Daniel/src/scratch/tox-and-venvs/py27-env/bin/python2.7 py27-env'

The path /Users/Daniel/src/scratch/tox-and-venvs/py27-env/bin/python2.7 (from --python=/Users/Daniel/src/scratch/tox-and-venvs/py27-env/bin/python2.7) does not exist

ERROR: Error creating virtualenv. Note that some special characters (e.g. ':' and unicode symbols) in paths are not supported by virtualenv. Error details: InvocationError('/usr/local/opt/python/bin/python3.6 -m virtualenv --python /Users/Daniel/src/scratch/tox-and-venvs/py27-env/bin/python2.7 py27-env (see /Users/Daniel/src/scratch/tox-and-venvs/py27-env/log/py27-env-0.log)', 3)
```

I noticed that the change in the MD5 sum appears to have triggered the recreation. I confirmed that the virtual environment's python 2.7 and the system's python 2.7 do indeed have those two different MD5 sums that are listed in tox's output. Here is the part I don't understand: the MD5 sums for the other virtual environment's python 3.6 and the system's python 3.6 also differ, but when the 3.6 environment is active, tox doesn't try to recreate it! The system's python 3.6 has an MD5 sum of 631e2862c29aaf84e07aece6bba1f0de, but the virtual environment's is ecda41b60670d580a842d27d937ce8b6.

Why is it that tox tolerates the difference in MD5 sums for the 3.6 environment, but not for the 2.7 one? My hope is that I'll be able to have tox ignore the different MD5 sums in the 2.7 environment as well, as the current behavior is breaking the development workflow for our data scientists because they cannot use tox to run tests when their 2.7 environment is active.

Thank you for your time.

Respecfully,

Dan Lidral-Porter | Data Scientist Sr
121 SW Salmon St., Suite 750, Portland, OR 97204
cylance.com

-------------------------------------------------------------------------------

PS: contents of attached tox.ini file (in case attachment is removed):

[tox]
envlist = env,py27-env
skipsdist = True

[testenv]
commands = python -c 'print("Hello, World!")'

[testenv:env]
envdir = env
basepython = python3.6

[testenv:py27-env]
envdir = py27-env
basepython = python2.7


-------------- next part --------------
A non-text attachment was scrubbed...
Name: tox.ini
Type: application/octet-stream
Size: 212 bytes
Desc: tox.ini
URL: <http://lists.tox.chat/pipermail/support/attachments/20190114/521e37fd/attachment.obj>


More information about the Support mailing list