tox always uses python 2.7 to build envs. can't work on projects with python3 code in

Issue #334 on hold
Conrad NA created an issue

I've added the following to my

import sys
with open("", "w") as f:
    f.write(str(sys.version_info) + "\n")

my tox file looks like this:

envlist = py35

deps =

skip_install = true
skipsdist = true
deps =
commands = mypy --py2 zulip

and the following gets written out:

$ cat
sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

This is a problem because the project I'm trying to add tox to uses a module found only in python3.

GLOB sdist-make: /Users/cdean/dev/foss/python/zulip/api/
ERROR: invocation failed (exit code 1), logfile: /Users/cdean/dev/foss/python/zulip/api/.tox/log/tox-0.log
ERROR: actionid: tox
msg: packaging
cmdargs: ['/usr/local/opt/python/bin/python2.7', local('/Users/cdean/dev/foss/python/zulip/api/'), 'sdist', '--formats=zip', '--dist-dir', local('/Users/cdean/dev/foss/python/zulip/api/.tox/dist')]
env: None

Traceback (most recent call last):
  File "", line 9, in <module>
    from typing import Any, Generator, List, Tuple
ImportError: No module named typing

ERROR: FAIL could not package project - v = InvocationError('/usr/local/opt/python/bin/python2.7 /Users/cdean/dev/foss/python/zulip/api/ sdist --formats=zip --dist-dir /Users/cdean/dev/foss/python/zulip/api/.tox/dist (see /Users/cdean/dev/foss/python/zulip/api/.tox/log/tox-0.log)', 1)

What am I doing wrong here?

Comments (4)

  1. Sebastian Noack

    Apparently, tox builds the package (i.e. runs sdist) once using the same interpreter that runs tox itself. Then it installs the package inside each virtualenv along the dependencies, and runs any command using the corresponding Python interpreter. FWIW, I agree this behavior isn't great, not only in your case, but it generally means that is never tested with different Python versions. As a workaround, you can call explicitly rather than having tox handle the packaging:

    envlist = py35
    skipsdist = True
    commands =
        python install

    Another workaround, in your case, would be to install and run tox itself with Python 3.

  2. Log in to comment