5

I want to know how correctly convert py documents to C with help Cython But all the time a have some error.

D:\Cython\test4>python setup.py build_ext --inplace
running build_ext
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(ext_modules = cythonize('hello.pyx', compiler_directives={'language_level': 3}))
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\command\build_ext.py", line 306, in run
    self.compiler = new_compiler(compiler=self.compiler,
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\ccompiler.py", line 1032, in new_compiler
    return klass(None, dry_run, force)
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\cygwinccompiler.py", line 282, in __init__
    CygwinCCompiler.__init__ (self, verbose, dry_run, force)
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\cygwinccompiler.py", line 157, in __init__
    self.dll_libraries = get_msvcr()
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38\lib\distutils\cygwinccompiler.py", line 86, in get_msvcr
    raise ValueError("Unknown MS Compiler version %s " % msc_ver)
ValueError: Unknown MS Compiler version 1916

I have hello.pyx file, which includes this code

cpdef int test(int x):
    cdef int y = 1
    cdef int i
    for i in range(1, x+1):
        y *= i
    return y

Setup.py file includes

   from distutils.core import setup 
   from Cython.Build import cythonize
   setup(ext_modules = cythonize('hello.pyx', compiler_directives={'language_level': 3}))

Microsoft Visual Studio has installed, gcc compiler also installed. What should I do?

Alex97
  • 73
  • 2
  • 9
  • It seems to be related to the MS Compiler; I am not sure what the problem is, but you could try to do that from the Visual Studio Developer Command Prompt. – zmb Feb 20 '20 at 14:59
  • 1
    You need to get a supported compiler. MinGW works only till Python3.4: https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29 – ead Feb 20 '20 at 15:43
  • 2
    Is this just the usual issue that you need need a specific version of the Windows compiler to match the one Python was built with https://wiki.python.org/moin/WindowsCompilers – DavidW Feb 20 '20 at 15:44

1 Answers1

3

Hey I found simple solution. Just install Microsfot Visual Studio (community version works). Make sure you got MSVC and Windows 10 SDK checked. I was told both are required.

Select Desktop C++ development:

enter image description here

Select MSVC and Win10 SDK:

enter image description here

After install restart pc. It should compile with python setup.py build_ext --incplace

Grzegorz Krug
  • 186
  • 2
  • 11