20

I am trying to run some code with Python 3.5 on Windows 10 with the use of cygwin (mingw). To be precise I am using the PyDSTool module, where I call the dopri integrator. The problem is, I am having trouble with distutils not recognizing Microsoft Visual Studio 2015. Is there a way to avoid this (without going back to older versions of Python, Windows, Visual Studio). The full Error can be seen bellow.

ValueError                                Traceback (most recent call last)
<ipython-input-16-bfeb915bfd7b> in <module>()
     60 print("\n")
     61 
---> 62 testODE = Dopri_ODEsystem(DSargs)
     63 
     64 print('Integrating...')

C:\Anaconda3\lib\site-packages\PyDSTool\Generator\Dopri_ODEsystem.py in __init__(self, kw)
    371             print("stages using the makeLibSource and compileLib methods.")
    372         else:
--> 373             self.makeLib()
    374 
    375     @property

C:\Anaconda3\lib\site-packages\PyDSTool\Generator\mixins.py in makeLib(self, libsources, libdirs, include)
     98             self.forceLibRefresh()
     99         self.makeLibSource(include)
--> 100         self.compileLib(libsources, libdirs)
    101 
    102     @property

C:\Anaconda3\lib\site-packages\PyDSTool\Generator\mixins.py in compileLib(self, libsources, libdirs)
     78           precompiled libraries."""
     79 
---> 80         self._builder.build(libsources, libdirs, self._compiler)
     81 
     82     def forceLibRefresh(self):

C:\Anaconda3\lib\site-packages\PyDSTool\Generator\mixins.py in build(self, libsources, libdirs, compiler)
    187                   script_args=script_args,
    188                   ext_modules=[extmod],
--> 189                   py_modules=[self.modname])
    190 
    191     def save_vfield(self, code, fname=None):

C:\Anaconda3\lib\site-packages\numpy\distutils\core.py in setup(**attr)
    167     new_attr['distclass'] = NumpyDistribution
    168 
--> 169     return old_setup(**new_attr)
    170 
    171 def _check_append_library(libraries, item):

C:\Anaconda3\lib\distutils\core.py in setup(**attrs)
    146     if ok:
    147         try:
--> 148             dist.run_commands()
    149         except KeyboardInterrupt:
    150             raise SystemExit("interrupted")

C:\Anaconda3\lib\distutils\dist.py in run_commands(self)
    953         """
    954         for cmd in self.commands:
--> 955             self.run_command(cmd)
    956 
    957     # -- Methods that operate on its Commands --------------------------

C:\Anaconda3\lib\distutils\dist.py in run_command(self, command)
    972         cmd_obj = self.get_command_obj(command)
    973         cmd_obj.ensure_finalized()
--> 974         cmd_obj.run()
    975         self.have_run[command] = 1
    976 

C:\Anaconda3\lib\site-packages\numpy\distutils\command\build_ext.py in run(self)
    115                                      verbose=self.verbose,
    116                                      dry_run=self.dry_run,
--> 117                                      force=self.force)
    118         self.compiler.customize(self.distribution)
    119         self.compiler.customize_cmd(self)

C:\Anaconda3\lib\site-packages\numpy\distutils\ccompiler.py in new_compiler(plat, compiler, verbose, dry_run, force)
    594         raise DistutilsModuleError(("can't compile C/C++ code: unable to find class '%s' " +
    595                "in module '%s'") % (class_name, module_name))
--> 596     compiler = klass(None, dry_run, force)
    597     log.debug('new_compiler returns %s' % (klass))
    598     return compiler

C:\Anaconda3\lib\site-packages\numpy\distutils\mingw32ccompiler.py in __init__(self, verbose, dry_run, force)
     56 
     57         distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose,
---> 58                                                             dry_run, force)
     59 
     60         # we need to support 3.2 which doesn't match the standard

C:\Anaconda3\lib\distutils\cygwinccompiler.py in __init__(self, verbose, dry_run, force)
    159             # Include the appropriate MSVC runtime library if Python was built
    160             # with MSVC 7.0 or later.
--> 161             self.dll_libraries = get_msvcr()
    162 
    163     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):

C:\Anaconda3\lib\distutils\cygwinccompiler.py in get_msvcr()
     88         #     return ['vcruntime140']
     89         else:
---> 90             raise ValueError("Unknown MS Compiler version %s " % msc_ver)
     91 
     92 

ValueError: Unknown MS Compiler version 1900 
0

6 Answers 6

20

I made the following changes and it worked for me with the following configurations.

  • OS : Win 7 Prof. SP1 64 bit
  • CPython 3.6 , 64 Bit
  • Mingw 64 (x86_64-7.1.0-posix-seh-rt_v5-rev0)
  • Cython 0.25.2

I did the following

  1. Add mingw in the PATH variable (C:\mingw-w64\x86_64-7.1.0-posix-seh-rt_v5-rev0\mingw64\bin for me)
  2. Test by opening command line and command gcc works ( I have no other compilers)
  3. Create distutils.cfg in C:\Python36\Lib\distutils
  4. Add lines in that file:

    [build]
    compiler = mingw32
    
  5. Manually applying this patch

  6. Manually downloading the file vcruntime140.dll and putting it in C:\Python36\libs
Sign up to request clarification or add additional context in comments.

5 Comments

Evrything worked fine this way till I found that MingW w64 defines "hypot = hypot" and in pyconfig.h , it is defined as "hypot = _hypot". Hence generating compiler errors in some cases. The fix is: 1) Either temporarily edit pyconfig.h with making the line "#define hypot _hypot" to "#define hypot hypot", and then run the cython process. 2) In setup.py, add a new param to "ext = Extension("...",..,..,extra_compile_args=['...', '-D_hypot=hypot', '..'])" ... This problem specifically happens when there is a C++ compile with the Cython code, it appears.
I can confirm that this works on Windows 10 with Anaconda 3
If you cant make it work give compiler=mingw32.exe a try also - it worked for me, while compiler=mingw32 didn't.
PS: If you are using anaconda, just copy vcruntime140.dll from D:\Anaconda3\Library\bin\vcruntime140.dll to somewhere\Python3.6\libs
Hi, I try the same, but when I do in pyrfc: python setup.py install I get this error: error Microsoft Visual C 14.0 is required
10

Distutils and Numpy/Distutils currently do not have support for Visual Studio 2015, Visual C++ 14. Following tips drawn from the Python bug report, I was able to patch the necessary files and successfully build extension using a new install of Python 3.5 from Anaconda and Mingw64 with GCC 5.2.0 running within MSYS2 on Windows 7. I do not have Visual Studio installed. The solution was to patch one distutils file and two numpy/distutils files (if this applies). These patches have been submitted for inclusion in future revisions.

You can apply the patches yourself for a quick fix:

UPDATE

Please note that while the patches above worked for me it was not accepted for inclusion in upstream. The changes that came with VS 2015 are more complex than I appreciated.

Comments

9

If anyone still has this problem,i just ran into it while installing yowsup and python-axolotl, this is what i did to solve it:

1- Apply the patch from Tharen into the python cygwinccompiler.py file (located in your python installation folder) https://bugs.python.org/file40608/patch.diff

2-With mingw, install pexports, open a terminal in administrator mode and type:

mingw-get install pexports

2-Go to the python install folder, in my case it was C:\Program Files (x86)\Python36-32

still in the same terminal we used to install pexports, after navigating to the python install folder run the following:

pexports vcruntime140.dll >libs\vcruntime140.def
dlltool -dllname vcruntime140.dll --def libs\vcruntime140.def --output-lib libs\libvcruntime140.a

Then go back to the folder where you were installing the library, or whatever you were doing before, it should work now.

btw, dont forget to add

[build]
compiler = mingw32 

in the distutils file.

Source: this own post and https://bugs.python.org/issue25251

1 Comment

pexports is gendef in mingw-w64-i686-tools or mingw-w64-x86_64-tools under msys2 .
6

I was running on the same problem and figured out that the issue was with the mingw compiler. I tried the patches suggested by @tharen but it didn't work for me.

It seems that cygwin's favourite compiler for windows is the visual c++ so I downloaded just the visual c++ build tools from http://landinghub.visualstudio.com/visual-cpp-build-tools and then it worked fine.

Note that you will need to uninstall mingw and all references to it that you included in your project. In particular I had to delete a distutils.cfg file that I had created which had the following code pointing to mingw

[build]
compiler = mingw32

Comments

4

Details in link helped me resolve this like a charm.

Just commented get_msvcr() in cygwinccompiler.py.

(remember to comment the else also)

1 Comment

where is cygwinccompiler.py?
1

I just made he following changes and it worked like a charm!

Edit file distutils.cfg present in locations:

  1. C:\Users\\AppData\Local\Continuum\Anaconda3\Lib\distutils\
  2. C:\Users\\AppData\Local\Continuum\Anaconda3\pkgs\libpython-2.0-py36_0\Lib\distutils

Modify content of distutils.cfg to :

[build]
compiler=g++

[build_ext]           
compiler=g++

P.S. Probably changing only in 2nd location should also do.

P.P.S Make sure gcc is installed and is in PATH. For me , TDM-GCC-64 was installed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.