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

当前回答

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

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

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

其他回答

关于这个问题的最佳和详尽的答案如下:https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/

在大多数情况下,只要找到适合您所需的python依赖项的.whl包并使用pip安装它就足够了。

在最后一种情况下,您必须安装microsoft编译器并从源代码安装软件包。

2016年解决这一问题的最简单方法是安装Chocolatey,然后安装vcpython27包。打开Powershell:

> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y

看起来它正在寻找VC编译器,所以您可以尝试使用-c mingw32提及编译器类型,因为您有msys

python setup.py install -c mingw32

我想在Windows 10上使用Python 2.7运行pysph,但没有找到vcvarsall.bat(来自distutils)

我的解决方案如下:

安装Microsoft Visual C++for Python 2.7(如@Michael建议的那样)

在Windows 10上,它安装到(我的用户名是Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

将环境变量VS90COMNTOOLS设置为Visual C++for Python 2.7的安装路径(请参见上面的路径)。

如果仍然不起作用,则在模块中进行修改

C:/Python27/lib/distutils

文件msvc9compiler.py。在其中查找函数Find_vcvarsall并执行以下修改。

更换管路:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

with

productdir = os.path.join(toolsdir)

在我的案例中,这就是vcvarsall.bat所在的位置(请检查,vcvarsall.bat在您的安装中)。

我找到了解决方案。我也遇到了同样的问题和错误,安装“amara”。我安装了mingw32,但需要配置distutils。

我已经安装了Python 2.6。我将mingw32安装到C:\programs\mingw\将mingw32的bin目录添加到环境变量:append c:\programs\MinGW\bin;到PATH将位于C:\Python26\Lib\distutils\distutils.cfg的distutils.cfg文件编辑为:[生成]编译器=mingw32现在运行easy_install.exe amara。

确保通过打开新的cmd.exe来设置环境。