我尝试安装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
当前回答
查看您尝试安装的软件包的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,请在构建之前激活它。
其他回答
我遵守了指示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它帮助了我
我没有看到任何使用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
我也遇到过同样的问题,所以我将在这里讲述我的故事,希望它能帮助其他人解决同样的问题并节省我刚刚花的几个小时:
我在一个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的所有实例。”(从这里开始)
现在,我终于可以开始工作了。
看起来它正在寻找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在您的安装中)。