我尝试安装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
当前回答
当我尝试在python 3.5上安装numpy库时,遇到了这个问题。解决方案是安装VS2015。我有VS2008、2012、2013,它们都与python 3.5不兼容。显然,较新版本的python依赖于较新版本VS。
还要确保Visual Studio中安装了C++通用工具。
其他回答
您需要安装一个与用于构建Python的编译器兼容的Microsoft编译器。这意味着您需要Visual C++2008(或更高版本,有一些调整)。
微软现在提供了一个捆绑的编译器和头文件,以便能够在令人难忘的URL上编译Python扩展:
Microsoft Visual C++编译器Python 2.7版http://aka.ms/vcpython27
这是一个相对较小的包装;85MB可下载,无需管理员权限即可安装,无需重新启动。这个名字有点误导人,编译器适用于最初使用Visual C++2008编译的任何Python版本,而不仅仅是Python 2.7。
如果启动Python交互式提示或打印sys.version,请查找MSC版本字符串;如果是MSC v.1500,您可以使用此工具。
从最初的公告到distutils列表:
微软发布了Python 2.7的编译器包,使人们更容易在Windows上构建和分发C扩展模块。Microsoft Visual C++编译器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中正常工作。
请注意,您需要安装setuptools6.0或更高版本(在下载页面的系统要求中列出)。您正在安装的项目必须使用setuptools.setup(),而不是distutils,否则自动检测将无法工作。
微软表示,他们希望保持URL稳定,以便自动化脚本可以轻松引用它。
我有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))
我没有看到任何使用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
你可以用easy_install代替pip,这对我很有用。
Microsoft Visual C++编译器for Python 2.7位于http://www.microsoft.com/en-us/download/details.aspx?id=44266不是解决方案?