Visual C++ for Python failed with exit status 2

2019-02-14 16:18发布

问题:

  File "c:\users\user\appdata\local\temp\pip_build_user\ssdeep\.eggs\cff
i-1.8.2-py2.7-win32.egg\cffi\ffiplatform.py", line 65, in _build
    raise VerificationError('%s: %s' % (e.__class__.__name__, e))

cffi.ffiplatform.VerificationError: CompileError: command 'C:\\Users\\user\\
AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin
\\cl.exe' failed with exit status 2

Cleaning up... Command python setup.py egg_info failed with error code 1 in c:\users\


I keep getting this error. I have tried multiple other solutions on here but no luck. Am I missing something. Thanks

回答1:

A crude method worked for me. Perhaps someone with knowledge can optimize the answer:

  1. Read the following article Link
  2. Mine is Python 2.7. I followed the article and installed the Visual C++ compiler for python 2.7. Install Link
  3. This installs a folder in your "%AppData%\Local\Programs\Common\Microsoft".
  4. I copied the contents of
    • "...\Visual C++ for Python\9.0\VC\include"to the "C:\Python27\include"
    • "...\Visual C++ for Python\9.0\VC\lib"to "C:\Python27\libs"
    • "...\Visual C++ for Python\9.0\WinSDK\Include" to "C:\Python27\include"
    • "...\Visual C++ for Python\9.0\WinSDK\lib" to "C:\Python27\libs"
  5. I edited path in environmental variables to include these two directories ("C:\Python27\include" and "C:\Python27\libs". I think this step is not essential).
  6. Edit the "msvc9compiler.py" in the directory "C:\Python27\Lib\distutils"
    • Line # ~270 hard coded link to "vcvarsall.bat" "%appdata%..\Visual C++ for Python\9.0\vcvarsall.bat"
    • Line # ~394 os.environ['include'] = "C:\\Python27\\include"
    • Line # ~396 os.environ['lib'] = "C:\\Python27\\libs"
    • Line # ~402 hard coded the link to self.cc = "...\Visual C++ for Python\9.0\VC\Bin\cl.exe" (caution: it is \Bin and not \bin.)
    • Line # ~403 Similar to above hard coded the link to self.linker.

Doing the above steps worked for me.