我尝试安装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
当前回答
你可以用easy_install代替pip,这对我很有用。
其他回答
我也遇到过同样的问题,所以我将在这里讲述我的故事,希望它能帮助其他人解决同样的问题并节省我刚刚花的几个小时:
我在一个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的所有实例。”(从这里开始)
现在,我终于可以开始工作了。
您可以从安装编译版本http://www.lfd.uci.edu/~gohlke/pythonlibs/
我没有看到任何使用vswhere的答案,我认为这是自Visual Studio 15.2以来正确的方法。
下面是我运行vsvars64.bat的方法(我想这与vsvarsall类似)
def init_vsvars():
cprint("")
cprint_header("Initializing vs vars")
vswhere_path = r"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe"
vswhere_path = path.expandvars(vswhere_path)
if not path.exists(vswhere_path):
raise EnvironmentError("vswhere.exe not found at: %s", vswhere_path)
vs_path = common.run_process(".", vswhere_path,
["-latest", "-property", "installationPath"])
vs_path = vs_path.rstrip()
vsvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvars64.bat")
# common.run_process(".", vsvars_path, [])
os.system('"%s"' % vsvars_path)
run_process做了很多事情,但基本上归结为:
output = ""
process = subprocess.Popen(
commandline,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
for stdout_line in iter(process.stdout.readline, ""):
cprint(stdout_line)
output += stdout_line
process.stdout.close()
return_code = process.wait()
return output
我尝试了以上所有答案,但发现所有答案都不起作用,这可能是因为我使用的是Windows 8,并且安装了Visual Studio 2012。在这种情况下,这就是你要做的。
vcvarsall.bat文件位于此处:C: \Program Files(x86)\Microsoft Visual Studio 11.0\VC
只需选择文件并复制它。
然后转到以下目录:C: \Program Files(x86)\Microsoft Visual Studio 11.0\Common7\Tools
并粘贴文件。然后,一切都会好起来。
我有python 2.73和windows 7。对我有效的解决方案是:
将mingw32的bin目录添加到环境变量:用C:\programs\mingw\bin追加PATH;已创建distutils.cfg,位于C:\Python27\Lib\distutils\distutils.ccfg,包含:[生成]编译器=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))