To deal with MinGW not recognizing the -mno-cygwin flag anymore, remove the flag in C:\Python27\Lib\distutils\cygwincompiler.py line 322 to 326, so it looks like this:
MSC v.1000 -> Visual C++ 4.xMSC v.1100 -> Visual C++ 5MSC v.1200 -> Visual C++ 6MSC v.1300 -> Visual C++ .NETMSC v.1310 -> Visual C++ .NET 2003MSC v.1400 -> Visual C++ 2005 (8.0)MSC v.1500 -> Visual C++ 2008 (9.0)MSC v.1600 -> Visual C++ 2010 (10.0)MSC v.1700 -> Visual C++ 2012 (11.0)MSC v.1800 -> Visual C++ 2013 (12.0)MSC v.1900 -> Visual C++ 2015 (14.0)MSC v.1910 -> Visual C++ 2017 (15.0)MSC v.1911 -> Visual C++ 2017 (15.3)MSC v.1912 -> Visual C++ 2017 (15.5)MSC v.1913 -> Visual C++ 2017 (15.6)MSC v.1914 -> Visual C++ 2017 (15.7)MSC v.1915 -> Visual C++ 2017 (15.8)MSC v.1916 -> Visual C++ 2017 (15.9)
Download and install the corresponding version of Visual Studio C++ from the previous step. Additional notes for specific versions of VC++ are listed below.
Uncheck everything except Developer Tools >> Visual C++ Compilers to save time and disk space from installing SDK tools you otherwise don't need.
Notes for Visual Studio C++ 2010
According to Microsoft, if you installed Visual Studio 2010 SP1, it may have removed the compilers and libraries for VC++. If that is the case, download Visual C++ 2010 SP1 Compiler Update.
Suggestion: If you have both a 32- and 64-bit Python installation, you may also want to use virtualenv to create separate Python environments so you can use one or the other at a time without messing with your path to choose which Python version to use.
According to @srodriguex, you may be able to skip manually loading the batch file (Steps 4-6) by instead copying a few batch files to where Python is searching by following this answer. If that doesn't work, here are the following steps that originally worked for me.
Open up a cmd.exe
Before you try installing something which requires C extensions, run the following batch file to load the VC++ compiler's environment into the session (i.e. environment variables, the path to the compiler, etc).
Execute:
32-bit Compilers:
Note: 32-bit Windows installs will only have C:\Program Files\ as expected
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
64-bit Compilers:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"
Note: Yes, the native 64-bit compilers are in Program Files (x86). Don't ask me why. Additionally, if you are wondering what the difference between vcvars64.bat and vcvarsx86_amd64.bat or more importantly the difference between amd64 and x86_amd64, the former are for the native 64-bit compiler tools and the latter are the 64-bit cross compilers that can run on a 32-bit Windows installation.
Update: If for some reason you are getting error: ... was unexpected at this time. where the ... is some series of characters, then you need to check that you path variable does not have any extraneous characters like extra quotations or stray characters. The batch file is not going to be able to update your session path if it can't make sense of it in the first place.
If that went well, you should get one of the following messages depending on which version of VC++ and which command you ran:
For the 32-bit compiler tools: Setting environment for using Microsoft Visual Studio 20xx x86 tools.
For the 64-bit compiler tools: Setting environment for using Microsoft Visual Studio 20xx x64 tools.
Now, run the setup via python setup.py install or pip install pkg-name
Hope and cross your fingers that the planets are aligned correctly for VC++ to cooperate.
但这不会为我安装,安装程序返回错误installation failed with return code 5100。我在以下链接找到了解决方案:http://support.microsoft.com/kb/2717426。简而言之,如果安装了较新版本的x86和x64 Microsoft VisualC++2010可再发行版本,它们与SDK安装程序中的冲突,需要先卸载。
然后安装了SDK,但我注意到vcvars64.bat仍然不存在于C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin中,也不是它的子文件夹。vcvarsall.bat运行vcvars64批处理文件,所以没有它,python包仍然无法安装(我忘记了此时显示的错误)。
File "numpy\core\setup.py", line 686, in get_mathlib_inforaise RuntimeError("Broken toolchain: cannot link a simple C program")RuntimeError: Broken toolchain: cannot link a simple C program