"Microsoft Visual C++ 14.0 is required" error

3,880 views
Skip to first unread message

david daviddavid

unread,
Jul 29, 2020, 2:13:46 AM7/29/20
to cython-users
I'm using cython-0.29.21 under Python 3.8.3 (under an Anaconda environment)
I have both the Microsoft Visual C++ x86 and x64 versions installed (14.26.28808.1)

I'm trying to run cython from the Anaconda Powershell (or command - tried both) windows
Working from another computer (which unfortunately isn't routinely available) the code builds fine
However I keep getting a fail with the error:
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

I've tried reinstalling Anaconda, Cython, and MSVC (repeatedly to see if installation order was the problem) but no change.
Since the reported error isn't the actual issue any suggestions for fixing it?


This is the full cython output

>python cythonMakeHotStrings.py build_ext --inplace
Compiling hotStringCore.pyx because it changed.
[1/1] Cythonizing hotStringCore.pyx
C:\Users\dgm55\anaconda3\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\dgm55\OneDrive\Documents\David\pythonScripts\Medical Scripts\hotStrings\hotStringCore.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'hotStringCore' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

mattip

unread,
Jul 29, 2020, 6:28:51 AM7/29/20
to cython-users

On Wednesday, 29 July 2020 at 09:13:46 UTC+3 dgm...@gmail.com wrote:
...
However I keep getting a fail with the error:
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

...

This is a general problem with compiling a c-extension module on python, and is not cython specific. If you run python -c"import sys; print(sys.version)" you should see the MSVC version used to compile python, for instance "MSC v.1924 64 bit (AMD64)" This is translated to a visual studio version, about 2/3 down this page you can see that 1924 corresponds to "Visual Studio 2019 Version 16.4". I imagine your python will report 1900. Using the exact same version of visual studio prevents possible problems due to mixing runtimes, which can mess up when allocating memory or handling errors, or in general touching global state.

You can choose which version of compiler to install via the "Visual Studio Install" app, choose "Modify" and then search for "msvc v140".

You can also choose to override this check, which could be dangerous. You can force python's distutils to accept your compiler. The easiest way to do this is to run the build from a "developer command prompt" dos window, which you can find via start->Visual Studio. Again, this is not recommended since it can lead to subtle problems that are almost impossible to debug.

This recommendation may have changed since the innovation of a "universal runtime", but I think that came after msvc v140.

Matti
 

david daviddavid

unread,
Jul 30, 2020, 2:42:04 AM7/30/20
to cython-users
Thank you.
With your suggestions I get:
(base) PS C:\Users\dgm55> python -c"import sys; print(sys.version)"
3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]

on the wiki page thats:
MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
(which admittedly surprised me as the Anaconda version which installed in the python is Anaconda3-2020.07-Windows-x86_64.exe - the computer is new)

reporting on my MSVC version 
(base) PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64> cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27034 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

So my reading is that the versions are appropriate, but the error still occurs

trying to run "python cythonMakeHotStrings.py build_ext --inplace" from the developer command prompt and I get literally nothing happening (nothing is even output to the term, it just instantly exits back to command prompt).

mattip

unread,
Aug 2, 2020, 6:06:15 AM8/2/20
to cython-users
On Thursday, 30 July 2020 at 09:42:04 UTC+3 dgm...@gmail.com wrote:

So my reading is that the versions are appropriate, but the error still occurs


Strange. What happens when you do:
"python -c "from distutils import msvccompiler as cc; print(cc.get_build_version())"?

trying to run "python cythonMakeHotStrings.py build_ext --inplace" from the developer command prompt and I get literally nothing happening (nothing is even output to the term, it just instantly exits back to command prompt).

That command looks a bit messed up. Copy-paste problems? Did you mean "python setup.py build_ext --inplace"?

Matti

david daviddavid

unread,
Aug 2, 2020, 9:16:02 AM8/2/20
to cython-users
Oh looks like that was part of it.
I had left 14.2 installed as it was being used for something else but very oddly 14.1 wasn't installed (even though it was reported). However uninstalling 14.2 and just leaving 14.0 has eliminated that error (even if I still can't build as I now get the following. 


python setup.py build_ext --inplace
running build_ext
building 'hotStringCore' extension
creating build
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\dgm55\anaconda3\include -IC:\Users\dgm55\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" /TchotStringCore.c /Fobuild\temp.win-amd64-3.8\Release\hotStringCore.obj
hotStringCore.c
creating C:\Users\dgm55\OneDrive\Documents\David\pythonScripts\Medical Scripts\hotStrings\build\lib.win-amd64-3.8
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\dgm55\anaconda3\libs /LIBPATH:C:\Users\dgm55\anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" /EXPORT:PyInit_hotStringCore build\temp.win-amd64-3.8\Release\hotStringCore.obj /OUT:build\lib.win-amd64-3.8\hotStringCore.cp38-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.8\Release\hotStringCore.cp38-win_amd64.lib
hotStringCore.obj : warning LNK4197: export 'PyInit_hotStringCore' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.8\Release\hotStringCore.cp38-win_amd64.lib and object build\temp.win-amd64-3.8\Release\hotStringCore.cp38-win_amd64.exp
Generating code
Finished generating code
LINK : fatal error LNK1158: cannot run 'rc.exe'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1158

david daviddavid

unread,
Aug 2, 2020, 9:16:18 AM8/2/20
to cython-users
"python -c "from distutils import msvccompiler as cc; print(cc.get_build_version())" reports version: 
14.1

the "cythonMakeHotStrings.py" is a just a modified copy of setup.py as follows. On my previous computer that was working fine, and renaming it back to setup.py doesn't sort the error (I just tried just in case):
from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("hotStringCore.pyx")
)

david daviddavid

unread,
Aug 7, 2020, 6:58:18 AM8/7/20
to cython-users
I eventually got this to work (whew).
To build it required BOTH VS 14.0 and 14.2

I figured out why the 14.1 reporting oddity occurred - in the process of multiple install and uninstalls I had installed VS Buildtools and VS Community Studio. VS Community was the 14.1 installed and Buildtools had 14.2 and 14.0 (what a mess).
I think because I originally assumed that the cython error of missing 14.0 would mean >=14.0 and that the installed VSCS needed to be augmented by VSBT
Of course when I removed 14.1 and 14.2 the whole thing failed again. Eventually I figured that to work it requires the two different versions... 

Only took about 3 hours and 5GB of data - and all I really wanted was to build a few thousand lines of code - had I known the hassle I would have just written it in C to start with...

david daviddavid

unread,
Aug 7, 2020, 6:58:29 AM8/7/20
to cython-users
BTW for anyone who follows the actual Visual Studio components I needed were:-

Reply all
Reply to author
Forward
0 new messages