1

On Windows 10 Build 14393 with Python 3.7.0, Cython 0.29.6 and MinGW32 located at C:\MinGW with the path C:\MinGW\bin on the system PATH environment variable, I am unable to get Cython code to compile using MingW. When I attempt to, I receive the following:

running build_ext
building 'abc_image_stats' extension
error: Unable to find vcvarsall.bat
c:\program files\python\python37\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\abc\Downloads\python\abc_image_stats\abc_image_stats.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

I have tried various fixes, such as those mentioned here, to no avail. After making the config file as instructed in that solution, (but before changing cgwinccompiler.py), I attempted to compile again but then received this error:

running build_ext
Traceback (most recent call last):
  File "setup.py", line 7, in <module>
    include_dirs=[numpy.get_include()] # https://stackoverflow.com/a/14657667
  File "C:\Program Files\Python\Python37\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Program Files\Python\Python37\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Program Files\Python\Python37\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Program Files\Python\Python37\lib\distutils\command\build_ext.py", line 308, in run
    force=self.force)
  File "C:\Program Files\Python\Python37\lib\distutils\ccompiler.py", line 1031, in new_compiler
    return klass(None, dry_run, force)
  File "C:\Program Files\Python\Python37\lib\distutils\cygwinccompiler.py", line 282, in __init__
    CygwinCCompiler.__init__ (self, verbose, dry_run, force)
  File "C:\Program Files\Python\Python37\lib\distutils\cygwinccompiler.py", line 157, in __init__
    self.dll_libraries = get_msvcr()
  File "C:\Program Files\Python\Python37\lib\distutils\cygwinccompiler.py", line 86, in get_msvcr
    raise ValueError("Unknown MS Compiler version %s " % msc_ver)
ValueError: Unknown MS Compiler version 1914
c:\program files\python\python37\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\abc\Downloads\python\abc_image_stats\abc_image_stats.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

So then I did the last two steps; I added

elif msc_ver == '1914':
            # Visual Studio 2015 / Visual C 14.0
            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
            return ['vcruntime140']

to the cygwinccompiler.py file and copied vcruntime140.dll to the C:\Program Files\Python\Python37\libs folder, but then I receive this error upon attempting to compile:

running build_ext
building 'abc_image_stats' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall "-IC:\Program Files\Python\Python37\lib\site-packages\numpy\core\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" -c abc_image_stats.c -o build\temp.win-amd64-3.7\Release\abc_image_stats.o
In file included from C:\Program Files\Python\Python37\include/Python.h:68:0,
                 from abc_image_stats.c:4:
C:\Program Files\Python\Python37\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
 PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
                                                           ^~~~~~~
C:\Program Files\Python\Python37\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
     struct timeval *tv,
            ^~~~~~~
C:\Program Files\Python\Python37\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
     struct timeval *tv,
            ^~~~~~~
writing build\temp.win-amd64-3.7\Release\abc_image_stats.cp37-win_amd64.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-3.7\Release\abc_image_stats.o build\temp.win-amd64-3.7\Release\abc_image_stats.cp37-win_amd64.def "-LC:\Program Files\Python\Python37\libs" "-LC:\Program Files\Python\Python37\PCbuild\amd64" -lpython37 -lvcruntime140 -o C:\Users\abc\Downloads\python\abc_image_stats\abc_image_stats.cp37-win_amd64.pyd
C:\Program Files\Python\Python37\libs/libpython37.a: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
c:\program files\python\python37\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\abc\Downloads\python\abc_image_stats\abc_image_stats.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

To be clear, my setup.py file looks like this:

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

setup(
    ext_modules = cythonize("abc_image_stats.pyx"),
    include_dirs=[numpy.get_include()] # https://stackoverflow.com/a/14657667
)

and I am attempting to compile using python setup.py build_ext --inplace via the command line.

All I want to do is compile the Cython code on a Windows 10 machine using MingW. I've tried everything I can think of and don't know what's wrong. Any ideas on how to solve this?

joejoejoejoe4
  • 1,206
  • 1
  • 18
  • 38
  • Are you using a version of Python compiled with Mingw? If you aren't then I think it's incompatible. There was a project called Mingwpy that was compatible up to Python 3.4 but I think they ran into unsolvable issues after that. I'm not 100% up to date on this though – DavidW Mar 22 '19 at 07:18

1 Answers1

0

try to change

elif msc_ver == '1914':

    return ['vcruntime140']

to  return ['msvcr100']

this worked for me, don't really know why though

Sentouki
  • 85
  • 1
  • 9