Ilikepi739
Ilikepi739

Reputation: 31

Cython setup.py can't find installed Visual C++ Build Tools

I am attempting to build my cython code using this setup.py file:

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np

setup(
    name="My Cython Project",
    ext_modules=cythonize("*.pyx", include_path=[np.get_include()], language="c++")
)

and

python setup.py build_ext --inplace

But am getting the error:

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

But I installed the build tools and I know they work because I can manually build my project using these commands in the Developer Command Prompt for VS 2019:

cython -a -3 --cplus Myfile.pyx
cl /LD /O2 /EHsc [ include files ] Myfile.cpp [ python 3.8 lib ]

Why does cython think the build tools are not installed? Do I need to add something to PATH?

(I run the same project on my macOS machine with gcc installed and it works perfectly.)

Screenshot of my Visual Studio Installer Screen

Upvotes: 3

Views: 5322

Answers (1)

nefedor
nefedor

Reputation: 121

The problem is that setup.py shows you incorrect version of MSVC. It's not the 14.0 that you need. I just did solved the very same issue myself, also for Python 3.8, so here are the steps.

  1. When you compile something for Python, you should use the same compiler version. So let's see what compiler was used for you Python:

    python -c "import sys; print(sys.version)"

    Mine prints:

    3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]

    So I need MSVC version 1916.

  2. You can check which version it is here: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B . For me 1916 is Visual Studio 2017 version 15.9 - likely that's what you really need.

  3. You to M$ downloads https://my.visualstudio.com/Downloads?q=Visual%20Studio%202015&pgroup= , search, for example, for "Visual Studio Community 2017 (version 15.9)" and install it (or just the compiler) and enjoy.

P.S. It is likely that you will need exactly that compiler for all your python 3.8 extensions (unless you use direct dll calls) and you will need to recompile the code you did in Studio 2019.

Upvotes: 10

Related Questions