我尝试安装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

当前回答

使用此链接下载并安装Visual C++2015生成工具。它将自动下载visualcppbuildtools_full.exe并安装Visual C++14.0,而无需实际安装Visual Studio。安装完成后,重试pip安装,您将不会再次出现错误。

我已经在以下平台和版本上测试了它:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

其他回答

当我尝试在python 3.5上安装numpy库时,遇到了这个问题。解决方案是安装VS2015。我有VS2008、2012、2013,它们都与python 3.5不兼容。显然,较新版本的python依赖于较新版本VS。

还要确保Visual Studio中安装了C++通用工具。

我也遇到过同样的问题,所以我将在这里讲述我的故事,希望它能帮助其他人解决同样的问题并节省我刚刚花的几个小时:

我在一个windows7盒子里有mingw(g++(GCC)4.6.1)和python 2.7.3,我正在尝试安装PyCrypto。

在运行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的所有实例。”(从这里开始)

现在,我终于可以开始工作了。

使用此链接下载并安装Visual C++2015生成工具。它将自动下载visualcppbuildtools_full.exe并安装Visual C++14.0,而无需实际安装Visual Studio。安装完成后,重试pip安装,您将不会再次出现错误。

我已经在以下平台和版本上测试了它:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

Microsoft Visual C++编译器for Python 2.7位于http://www.microsoft.com/en-us/download/details.aspx?id=44266不是解决方案?

如果您安装了mingw

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

有效,迫使pip使用mingw编译器而不是Microsoft的编译器进行编译。请参见此处https://github.com/pypa/pip/issues/18有关详细信息(上一篇文章)。