【问题标题】:Error compiling when installing with pip使用 pip 安装时编译出错
【发布时间】:2014-01-16 14:17:26
【问题描述】:

我在使用 pip 安装软件包时遇到问题。我在 Windows 8.1 64bit 上的 Pyzo 中运行 python 3.3(预打包有 numpy、scipy 等)。当我尝试使用 pip 安装需要编译一些 c 的软件包时,它失败了。

起初我收到错误“无法找到 vcvarsall.bat”。我查了一下,它似乎试图找到用于构建我正在运行的 python 版本的编译器。
error: Unable to find vcvarsall.bat
pip install gives error: Unable to find vcvarsall.bat
Unable to find VCVarsall.bat using Python 2.7
error: Unable to find vcvarsall.bat to compile python modules with Visual Studio 2008 installed

我正在为我的普通 .Net 东西运行 Visual Studio 2013,但显然 python 3.3 是用 Visual Studio 2010 编译的。所以,我安装了 Visual C++ 2010 express,但它仍然给出了同样的错误。

我设法找到了用于查找 vcvarsall 的源代码(Lib/distutils 中的 msvc9compiler.py)。所以我开始在源代码中四处寻找,发现它寻找的版本是 9.0(即 Visual 2008)。所以我下载了 2008 C++ Express 并再次尝试。这次它找到了 vcvarsall.bat 但我得到了一个不同的错误“ValueError:['path']” 抛出错误的方法如下。(打印是我添加的用于调试)

def query_vcvarsall(version, arch="x86"):
"""Launch vcvarsall.bat and read the settings from its environment
"""
vcvarsall = find_vcvarsall(version)
print(version)
print(arch)
print(vcvarsall)
interesting = set(("include", "lib", "libpath", "path"))
result = {}

if vcvarsall is None:
    raise DistutilsPlatformError("Unable to find vcvarsall.bat")
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
try:
    stdout, stderr = popen.communicate()
    if popen.wait() != 0:
        raise DistutilsPlatformError(stderr.decode("mbcs"))

    stdout = stdout.decode("mbcs")
    for line in stdout.split("\n"):
        print(line)
        line = Reg.convert_mbcs(line)
        if '=' not in line:
            continue
        line = line.strip()
        key, value = line.split('=', 1)
        key = key.lower()
        if key in interesting:
            if value.endswith(os.pathsep):
                value = value[:-1]
            result[key] = removeDuplicates(value)

finally:
    popen.stdout.close()
    popen.stderr.close()

if len(result) != len(interesting):
    print(str(result)+"::: "+str(interesting))
    raise ValueError(str(list(result.keys())))

return result

所以基本上,发生的事情是它检查我的环境变量并查找有趣的条目(“include”、“lib”、“libpath”、“path”) 现在,我拥有的唯一一个是“路径”,所以最后的 if 语句会抛出 ValueError。 所以,我想知道的是其他的是什么,为什么我没有它们,它为什么要寻找它们,我该如何解决?

感谢所有答案。

问候
弗雷德里克

【问题讨论】:

  • arch 打印什么?
  • 嗨,它会打印“amd64”。

标签: python visual-studio python-3.x pip


【解决方案1】:

问题在于 Visual C++ Express 2010 不包含 64 位编译器。见How to compile a 64-bit application using Visual C++ 2010 Express

【讨论】:

  • 我们是否需要 Visual Studio 才能在 python 中安装包?为什么 pip 不使用像 R 这样的预编译二进制文件?
  • @MajidEinian Pip 是一个源代码分发版。我猜是因为支持的平台数量巨大,所以作者预编译是不可行的。
  • @Fred_F,这个解决方案对你有用吗?它似乎对我没有帮助。
  • @clg4 您是否使用了 64 位命令提示符?如果您不需要 Python 3,您还可以查看 Microsoft Visual C++ Compiler for Python 2.7 是否适合您。
  • @jwalker 是的。 Windows 7 中的命令提示符默认为 64 位。感谢您的尝试
猜你喜欢
  • 2015-10-08
  • 2021-01-23
  • 2018-10-04
  • 2019-06-14
  • 2017-12-22
  • 2021-03-06
  • 2013-01-26
  • 2016-06-04
相关资源
最近更新 更多