Setuptools: Obsolete error message when MS Visual C++ Build Tools missing

Created on 4 Aug 2020  路  4Comments  路  Source: pypa/setuptools

Environment

  • pip version: 20.2.1
  • Python version: 3.8.3
  • OS: Windows 10 (fully patched, on latest release)

Description

When installing a module that needs Microsoft's Visual C++ Build Tools, and these tools are not present, this message is displayed:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

This message is erroneous for a few reasons:

In my case, I no longer got this error after adding C++ support to my Visual Studio 2017 installation per the link above. That validates that:

  1. the build tools can be installed as a component of Visual Studio instead of separately
  2. version 14 is not strictly required (Visual Studio 2017 = version 15.9.25)

Expected behavior

Error message wording should be accurate and not encourage undesirable choices.

How to Reproduce

Install a package that needs to be compiled with C++. For example: python -m pip install wordcloud

Output

The output ends with this:

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
good first issue help wanted

Most helpful comment

Feel free to send a PR. The code is here.

All 4 comments

Feel free to send a PR. The code is here.

Done! PR ready.

Thinking ahead--is Python's documentation an appropriate place for this info? The links, version requirements, etc. are volatile, so I wonder if the code should just have a link to the appropriate Python doc URL?

The remark "version 14 is not strictly required" is quite untrue in practice.

Method MSVCCompiler.query_vcvarsall() determines if there is a compiler installed by searching for the file vcvarsall.bat, which exists in 14.2. Failing that, it then recommends the user download Visual C++ 14.2, which is no longer readily available. It _can_ be downloaded, but only if you have a paid subscription. The link in the error message points to https://visualstudio.microsoft.com/downloads/ which does indeed work, but the only compiler available free from that page is Visual Studio 2019 (a.k.a. version 16). That compiler does not satisfy the query_vcvarsall() test because the counterpart of vcvarsall.bat in 16.0 is VsDevCmd.bat.

In fact even if you have VC++ 14.2, distutils still gets things wrong, presumably holdovers from earlier versions of VC++.
First one must work out the correct values for environment variables LIBPATH and INCLUDE. After that, to make a compile work using the command lines that distutils issues, it is also necessary to copy the contents of C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64 and C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64 to a new folder Pythonxx\PCBuild\amd64 which distutils puts as a LIBPATH parameter to link.exe but which does not actually exist. Likewise it is necessary to copy C:\Program Files (x86)\Windows Kits\10\bin\x64\rc.exe to an existing folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64 because distutils knows the executable is there but Microsoft reckons otherwise.

All of this probably a doddle if you are a seasoned MSC programmer, but (I speak from experience) painful to someone who switched from C to Python around the time when Visual C 3 came out. And quite out of reach for a Python beginner who gets this message from PIP when he tries to install numpy. That happened today.

So it is not just the message that is obsolete: the whole of distutils.msvc9compiler needs attention paid not just to what it says but to what it does. It is of course entitled to insist on one and only one MS compiler to do what it does, but it must be one that is readily available, and the command lines it issues should work on a vanilla installation of that compiler, without the user having to modify the folder layout to put files where distutils expects them to be.

@BoarGules great observations. You may be right, and if so, the wording change I suggested may need further revision.

This confirms what I wrote in https://github.com/pypa/setuptools/issues/2302#issuecomment-674564732, that this really needs to be documented in web documentation, and Python merely include a link to that document. Then further revisions just need a web edit instead of a new build.

Was this page helpful?
0 / 5 - 0 ratings