我尝试安装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
当前回答
我遵守了指示http://springflex.blogspot.ru/2014/02/how-to-fix-valueerror-when-trying-to.html.但什么都没发生。然后我安装了2010 Visual Studio Express(http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)遵循建议http://blog.python.org/2012/05/recent-windows-changes-in-python-33.html它帮助了我
其他回答
查看您尝试安装的软件包的setup.py文件。如果它是一个较旧的包,那么它可能正在导入distutils.core.setup()而不是setuptools.setup)。
我(在2015年)结合了这些因素:
来自的Microsoft Visual C++编译器Python 2.7http://aka.ms/vcpython27使用distutils.core.setup()的旧包尝试使用python setup.py构建,而不是使用pip。
如果您使用最新版本的pip,它将强制(monkeypatch)包使用setuptools,即使其setup.py调用distutils。但是,如果您不使用pip,而是只使用python setup.py构建,那么构建过程将使用distutils.core.setup(),它不知道编译器的安装位置。
解决方案
步骤1:打开相应的Visual C++2008命令提示符
打开“开始”菜单或“开始”屏幕,搜索“Visual C++2008 32位命令提示符”(如果您的python是32位)或“Visual C++200864位命令提示符(如果您是64位)”。运行它。命令提示符应显示Visual C++2008。。。在标题栏中。
步骤2:设置环境变量
在刚刚打开的命令提示符中设置这些环境变量。
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
参考http://bugs.python.org/issue23246
步骤3:构建和安装
cd到要构建的包,然后运行pythonsesetup.pybuild,然后运行python setup.pyinstall。如果要安装到virtualenv,请在构建之前激活它。
2016年解决这一问题的最简单方法是安装Chocolatey,然后安装vcpython27包。打开Powershell:
> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y
@monkey给出的答案是正确的答案之一,但不完整。
如果您想使用MinGW,您应该选择C、C++以及MinGW安装过程中建议的其他开发工具,以获得“make.exe”
您还必须在env中将路径设置为make.exe。
要完成他的回答,请执行以下步骤:
将mingw32的bin目录添加到环境变量中追加C:\Programs\MinGW\bin;C: \Programs\MinGW\msys\1.0\bin;到PATH将位于C:\Python26\Lib\distutils\distutils.cfg的distutils.cfg文件编辑(如果不存在则创建)为:[生成]编译器=mingw32
确保通过打开新的cmd.exe来设置环境变量。
当我尝试在windows 10中安装panda时,也出现了同样的错误。在搜索了几个解决方案后,我最终使用了轮子。
首先,将pip升级到最新版本:
easy_install install -U pip
第二,安装车轮:
pip install wheel
第三,下载软件包的whl文件并安装:
pip install [xxx].whl
到目前为止,我认为wheel是在windows上安装Python包的最佳方式。
我没有看到任何使用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