Skip to content

setuptools' discovery of MSVC fails in tox environment #1673

@StefanD986

Description

@StefanD986

Description

I stumbled upon a hard to debug issue when using tox to kick of builds that produce native artifacts using setuptools and Microsoft Visual Studio.

setuptools relies on the presence of some environment variables to locate vswhere.exe which is used to find the path to the msvc toolchain. setuptools.msvc uses the following environment variables to build the path to vswhere.exe

  • ProgramFiles
  • ProgramFiles(x86)

vswhere.exe in turn itself relies on some environment variables to locate the msvc toolchain. I tried and it looks like it only requires the ProgramData environment variable

TLDR

Without the presence of these three environment variables

  • ProgramFiles
  • ProgramFiles(x86)
  • ProgramData

the discovery of the msvc toolchain fails. It is hard to debug because setuptools doesn't give much diagnostic output.

Steps to reproduce

  1. Create a tox.ini with the following content:

    [tox]
    
    [testenv]
    skip_install=True
    commands =
        python -c "import setuptools;print(setuptools.msvc.msvc14_get_vc_env('amd64'))"
  2. Run tox

  3. Observe output

Expected behaviour

I expect the tox run to complete sucessfully

Actual behaviour

Run fails with

python run-test: commands[0] | python -c 'import setuptools;print(setuptools.msvc.msvc14_get_vc_env('"'"'amd64'"'"'))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\stefan\PycharmProjects\tox_msvc_bug\.tox\python\lib\site-packages\setuptools\msvc.py", line 314, in msvc14_get_vc_env
    return _msvc14_get_vc_env(plat_spec)
  File "C:\Users\stefan\PycharmProjects\tox_msvc_bug\.tox\python\lib\site-packages\setuptools\msvc.py", line 269, in _msvc14_get_vc_env
    "Unable to find vcvarsall.bat"
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
ERROR: InvocationError for command 'C:\Users\stefan\PycharmProjects\tox_msvc_bug\.tox\python\Scripts\python.EXE' -c 'import setuptools;print(setuptools.msvc.msvc14_get_vc_env('"'"'amd64'"'"'))

Potential Resolution

There are already a couple of environment variables that are passed through by default. I leave it up to discussion whether this usecase warrants adding the mentioned three variables to the default passthrough on windows platforms.

At the very least it would be nice to document that these environment variables need to be passed through in the tox docs, so that it can be found if users run into this issue and to mention keywords such as cython, vcvarsall.

What do you think?

Additional info

Output of tox -rvv: log.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions