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 .\
generating .\_example.c
(already up-to-date)
running build_ext
building '_example' extension
Traceback (most recent call last):
  File ".\", line 22, in <module>
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\", line 684, in compile
    compiler_verbose=verbose, debug=debug, **kwds)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\", line 1484, in recompile
    compiler_verbose, debug)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\", line 20, in compile
    outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\cffi\", line 49, in _build
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\", line 972, in run_command
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\", line 340, in run
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\", line 449, in build_extensions
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\command\", line 499, in build_extension
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\", line 473, in compile
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\", line 383, in initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\Program Files (x86)\Anaconda2\lib\distutils\", 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:

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:

Comments (3)

  1. Armin Rigo

    This is supposed to be fixed already: see function _hack_at_distutils() inside cffi/ 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