【问题标题】:How do I point easy_install to vcvarsall.bat?如何将 easy_install 指向 vcvarsall.bat?
【发布时间】:2011-09-26 23:03:20
【问题描述】:

我已经安装了 MSVC++ 2010 Express,并且我的 vcvarsall.bat 文件位于 C:\Program Files\Microsoft Visual Studio 10.0\VC,它位于我的系统 PATH 中。当我运行easy_install 时,它找不到vcvarsall.bat。

我需要在 distutils.cfg 文件中设置什么以将其指向我的 MSVC++ 安装吗?

G:\>easy_install hg-git
install_dir C:\Python26\Lib\site-packages\
Searching for hg-git
Best match: hg-git 0.2.6
Processing hg_git-0.2.6-py2.6.egg
hg-git 0.2.6 is already the active version in easy-install.pth

Using c:\python26\lib\site-packages\hg_git-0.2.6-py2.6.egg
Processing dependencies for hg-git
Searching for dulwich>=0.6.0
Reading http://pypi.python.org/simple/dulwich/
Reading http://samba.org/~jelmer/dulwich
Reading http://launchpad.net/dulwich
Best match: dulwich 0.7.1
Downloading http://www.samba.org/~jelmer/dulwich/dulwich-0.7.1.tar.gz
Processing dulwich-0.7.1.tar.gz
Running dulwich-0.7.1\setup.py -q bdist_egg --dist-dir c:\docume~1\mlin\locals~1
\temp\easy_install-fhraep\dulwich-0.7.1\egg-dist-tmp-qozily
error: Setup script exited with error: Unable to find vcvarsall.bat

【问题讨论】:

  • AFAIK,您需要 MSVC++ 2008 来安装需要 C/C++ 编译器的扩展,因为在 Windows 上构建 Python 已经有一段时间了。由于 MS 运行时库问题,不同版本的编译器不能混合使用。您仍然可以从here 下载 2008 Express Edition。
  • 感谢您指出这一点,马蒂诺。我通过使用 MinGW gcc 编译器解决了我的特定问题,因为它比安装 MSVC++ 2008 更快。我仍然想知道在哪里设置对 vsvarsall.bat 的引用...
  • 这是一个解决方法,使用 MinGW gcc:gist.github.com/1059280
  • 更新: 我为 MSVC++ 2008 提供的链接现在显示“抱歉。此下载不再可用。您选择的下载已停用。”所以看起来使用 MinGW gcc 是要走的路。
  • 还要注意切换到mingw32编译器doesn't work for all extensions.

标签: python distutils easy-install visual-studio-2010


【解决方案1】:

我仍然想知道在哪里设置对 vsvarsall.bat 的引用...

嗯,正如 martineau 所写,您必须安装 Visual Studio 2008 或 Visual C++ Express。话虽如此,我知道您想知道 Python 在哪里查找此批处理文件。您可以通过查看 distutils/msvc9compiler.py 标准模块中的 find_vcvarsall 函数的 definition 来看到这一点。 Python 依次检查注册表项下是否有任何文件夹保存

  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VCExpress\9.0\Setup\VC\ProductDir

(对于 64 位 Windows)或

  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
  • HKEY_LOCAL_MACHINE\Software\Microsoft\VCExpress\9.0\Setup\VC\ProductDir

(对于 32 位 Windows)存在,如果存在,它会将此类文件夹视为包含 vcvarsall.bat 文件的文件夹。如果这些文件夹都不存在,Python 检查是否有环境变量VS90COMNTOOLS。如果此变量退出,Python 会将高于此变量值两级的文件夹视为包含vcvarsall.bat 文件的文件夹。

另请参阅我的other 回答,它解释了为什么不能使用 MSVC++ 2010 为 Python 2.6 构建扩展

编辑: VC++ 2008 文件现在打包在 MS 的安装程序中,可以从here 下载。安装后 vcvarsall.bat 将位于C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

【讨论】:

  • 太糟糕了 Python 没有与 gcc 捆绑在一起。下载 3.3GB VS 2008 iso 只是为了能够在 64 位 Windows 和 64 位 Python 上使用 setuptools 有点荒谬。
  • @tponthieux 这就是为什么 Windows 上二进制包中的installation 如此方便。
  • @PiotrDobrogost 是的。但是 pypi 上的许多软件包都没有预编译的二进制安装程序,因此从源代码安装是唯一的选择。
  • 由于 MSVC++ 2008 Express 不再可用,他们应该将 Windows 版本更新为仍然可以获得的MSVC++ 2010 Express -- 尽管这样做会产生连锁反应...
  • @tponthieux "微软发布了一个 Python 2.7 编译器包,让人们更容易在 Windows 上构建和分发他们的 C 扩展模块。适用于 Python 2.7(又名 VC9)的 Microsoft Visual C++ 编译器是可从:aka.ms/vcpython27" "它是免费的(VC Express 2008 现在是在付费墙后面)它很小(85MB 下载,300MB 安装)它是每个用户安装,无需重新启动" - Steve Dower。公告见mail.python.org/pipermail/distutils-sig/2014-September/…
猜你喜欢
  • 2012-10-23
  • 2012-01-21
  • 2014-04-29
  • 2014-09-15
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
  • 2020-03-16
相关资源
最近更新 更多