我尝试安装Python软件包dulwich:
pip install dulwich
但我收到了一个晦涩的错误信息:
error: Unable to find vcvarsall.bat
如果我尝试手动安装该软件包,情况也是一样的:
> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat
我尝试安装Python软件包dulwich:
pip install dulwich
但我收到了一个晦涩的错误信息:
error: Unable to find vcvarsall.bat
如果我尝试手动安装该软件包,情况也是一样的:
> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat
对于Windows安装:
在安装软件包时运行setup.py时,Python 2.7会查找已安装的Visual Studio 2008。您可以通过在调用setup.py
之前设置正确的路径在VS90COMNTOOLS
环境变量中来欺骗Python使用更新的Visual Studio。
根据已安装的Visual Studio版本执行以下命令:
SET VS90COMNTOOLS=%VS100COMNTOOLS%
SET VS90COMNTOOLS=%VS110COMNTOOLS%
SET VS90COMNTOOLS=%VS120COMNTOOLS%
SET VS90COMNTOOLS=%VS140COMNTOOLS%
警告:如下所述,如果您正在尝试编译Python模块,则此答案不太可能有效。
有关详细信息,请参见在Windows上为Python 2.7构建lxml。
我找到了解决方法。我遇到了与安装“amara”时完全相同的问题和错误。我已经安装了mingw32,但需要配置distutils。
C:\programs\mingw\
c:\programs\MinGW\bin;
追加到PATH中编辑(如果不存在则创建)位于C:\Python26\Lib\distutils\distutils.cfg
的distutils.cfg文件,使其如下所示:
[build]
compiler=mingw32
现在运行easy_install.exe amara
。
确保通过打开新的cmd.exe
设置环境。
Run python.exe
to display which version of VC++ it was compiled with (example shown below).
It is important to use the corresponding version of the Visual C++ compiler that Python was compiled with since distilutils's
get_build_version
prevents mixing versions (per Piotr's warning).
Use the table below[1] to match the internal VC++ version with the corresponding Visual Studio release:
MSC v.1000 -> Visual C++ 4.x
MSC v.1100 -> Visual C++ 5
MSC v.1200 -> Visual C++ 6
MSC v.1300 -> Visual C++ .NET
MSC v.1310 -> Visual C++ .NET 2003
MSC 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.
For only the 32-bit compilers, download Visual Studio C++ 2008 Express Edition.
For the 64-bit compilers[2][3], download Windows SDK for Windows 7 and .NET Framework 3.5 SP1.
- Uncheck everything except
Developer Tools >> Visual C++ Compilers
to save time and disk space from installing SDK tools you otherwise don't need.
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.
If you don't need the Visual Studio IDE, download Visual Studio C++ 2015 Build Tools.
If you don't need the Visual Studio IDE, download Build Tools for Visual Studio 2017.
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.
打开一个 cmd.exe
命令行窗口。
在尝试安装需要 C 扩展的内容之前,请运行以下批处理文件,将 VC++ 编译器的环境加载到会话中(例如环境变量、编译器路径等)。
执行:
32 位编译器:
注意:32 位 Windows 安装将只有 C:\Program Files\
。
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
64 位编译器:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"
注意:是的,本机 64 位编译器位于 Program Files (x86)
中。不要问我为什么。
此外,如果您想知道 vcvars64.bat
和 vcvarsx86_amd64.bat
之间的区别,或者更重要的是 amd64
和 x86_amd64
之间的区别,则前者是本机 64 位编译器工具,后者是可以在 32 位 Windows 安装上运行的 64 位交叉编译器。
更新:
如果由于某种原因您收到 error: ... was unexpected at this time.
的错误消息,其中的 ...
是一系列字符,则需要检查您的路径变量是否有任何多余的字符,例如额外的引号或多余字符。如果批处理文件无法首先理解它,请不要指望它能更新您的会话路径。
如果成功了,您应该会收到以下两个版本的 VC++ 和运行的命令之一:
对于 32 位编译器工具:
正在设置使用 Microsoft Visual Studio 20xx x86 工具的环境。
对于 64 位编译器工具:
正在设置使用 Microsoft Visual Studio 20xx x64 工具的环境。
现在,通过 python setup.py install
或 pip install pkg-name
运行安装程序。
希望所有星球都对 VC++ 合作愉快。
setup.py
)安装此类软件包,则必须从源代码编译该C/C++代码。默认情况下,Pip会放肆地假设您已经安装了Microsoft Visual C++编译器。如果没有安装,则会看到此加密的错误消息“Error: Unable to find vcvarsall.bat”。最简单的解决方案是使用Christoph Gohlke提供的Windows安装程序(.msi)来安装常用的Python包。他为Python 2.x和3.x, 32位和64位建立了安装程序。您可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载它们。
这是一个相对较小的软件包,大小为85MB,可在不需要管理员权限的情况下安装并且不需要重新启动。虽然名称有点误导人,但该编译器可以用于任何最初使用Visual C++ 2008编译的Python版本,而不仅仅是Python 2.7。Microsoft Visual C++ Compiler for Python 2.7
请注意需要安装微软已经发布了一个针对Python 2.7的编译器包,使人们更容易在Windows上构建和分发他们的C扩展模块。Microsoft Visual C++ Compiler for Python 2.7(又名VC9)可以从以下网址获取:http://aka.ms/vcpython27
该软件包包含构建Python 2.7 32位和64位C扩展模块所需的所有工具和头文件(请注意,一些扩展模块需要第三方依赖项,例如OpenSSL或libxml2等不包含在内)。此外,还支持使用Visual C++ 2008构建的其他版本的Python,因此“Python 2.7”仅仅是广告 - 它也可以与2.6和3.2一起使用。
setuptools
6.0 或更新版本(在下载页面的系统要求中列出)。您安装的项目必须使用 setuptools.setup()
,而不是distutils
或自动检测将无法正常工作。
微软已经表示,他们希望保持URL稳定,以便自动化脚本可以轻松引用它。
我之前也遇到了这个问题,所以在这里分享我的经历,希望能帮助到其他遇到同样问题的人,并节省他们刚刚花费的几个小时:
在我安装 PyCrypto 的过程中,我使用了一个 Windows 7 系统下的 mingw (g++ (GCC) 4.6.1) 和 Python 2.7.3。
一切都从运行 setup.py install 命令时出现错误开始:
error: Unable to find vcvarsall.bat
在通过谷歌搜索错误后,很容易通过指定mingw作为首选编译器来解决问题:
setup.py install build --compiler=mingw32
问题是,然后我得到了一个不同的错误:configure: error: cannot run C compiled programs.
结果发现我的杀毒软件阻止了新编译的 .exe 文件的执行。我只需禁用杀毒软件的 "实时保护" 并继续处理下一个错误:
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
这解决了问题: "要么安装稍旧版本的MinGW,要么编辑Python目录下的distutils\cygwinccompiler.py文件,并删除所有-mno-cygwin实例。"(来源于这里)
现在,我终于可以开始工作了。
看起来它正在寻找 VC 编译器,所以你可以尝试使用 -c mingw32
来指定编译器类型,因为你有 MSYS。
python setup.py install -c mingw32
我有Python 2.73和Windows 7。对我有效的解决方案是:
C:\programs\mingw\bin;
创建位于C:\Python27\Lib\distutils\distutils.cfg
的distutils.cfg文件,其中包含:
[build]
compiler=mingw32
为了解决MinGW不再识别-mno-cygwin标志的问题,请在C:\ Python27 \ Lib \ distutils \ cygwincompiler.py行322到326中删除该标志,使其如下所示:
self.set_executables(compiler='gcc -O -Wall',
compiler_so='gcc -mdll -O -Wall',
compiler_cxx='g++ -O -Wall',
linker_exe='gcc',
linker_so='%s %s %s'
% (self.linker_dll, shared_option,
entry_point))
setup.py
文件中查找。如果它是一个旧版本,可能会导入 distutils.core.setup()
而不是 setuptools.setup()
。distutils.core.setup()
的旧版本软件包
3. 尝试执行 python setup.py build
而不是使用 pip
。setup.py
调用 distutils。但是,如果您没有使用pip,而是只运行python setup.py build
,则构建过程将使用distutils.core.setup()
,该过程不知道编译器的安装位置。
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
参考http://bugs.python.org/issue23246
步骤3:构建和安装
cd
到要构建的软件包中,然后运行python setup.py build
,接着运行python setup.py install
。如果你想要安装到虚拟环境中,请在构建之前激活虚拟环境。