CFFI Compile fails on Windows when using Microsoft Visual C++ Compiler for Python

Issue #346 resolved
Anonymous created an issue

When attempting to compile an extension module using CFFI, I get the following issue:

PS C:\GitProjects\cFFI Example> python .\example_build.py
generating .\_example.c
(already up-to-date)
running build_ext
building '_example' extension
Traceback (most recent call last):
  File ".\example_build.py", line 22, in <module>
    ffibuilder.compile(verbose=True)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\api.py", line 684, in compile
    compiler_verbose=verbose, debug=debug, **kwds)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\recompiler.py", line 1484, in recompile
    compiler_verbose, debug)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\ffiplatform.py", line 20, in compile
    outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\ffiplatform.py", line 49, in _build
    dist.run_command('build_ext')
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\build_ext.py", line 340, in run
    self.build_extensions()
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\build_ext.py", line 449, in build_extensions
    self.build_extension(ext)
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\build_ext.py", line 499, in build_extension
    depends=ext.depends)
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\msvc9compiler.py", line 473, in compile
    self.initialize()
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\msvc9compiler.py", line 383, in initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\msvc9compiler.py", line 271, in query_vcvarsall
    raise DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat

This appears to be a bug in distutils, and is documented here: https://bugs.python.org/issue23246

Unfortunately, it's tagged as wont' fix. However, setuptools does work.

It would be nice if the compile step could try to use setuptools if possible (since it does have better compiler detection). Baring that, including documentation on how to work around this would be fantastic. Cython has an excellent wiki page on this issue here:

https://github.com/cython/cython/wiki/CythonExtensionsOnWindows

Comments (3)

  1. Armin Rigo

    This is supposed to be fixed already: see function _hack_at_distutils() inside cffi/ffiplatform.py. I can confirm that it should have been called before dist.run_command('build_ext'). I have no clue why it doesn't seem to help in your case... Can you check if _hack_at_distutils() is really called? Maybe you are running in an setup where setuptools is not installed?

  2. etothepii

    You're correct - this is already fixed. I was using the version that was provided by Anaconda, and it was 1.10. Updating to the latest release solved the problem.

  3. Log in to comment