如何将easy_install指向vcvarsall.bat?
我已经安装了MSVC++ 2010 Express,并且我的vcvarsall.bat文件在C:\Program Files\Microsoft Visual Studio 10.0\VC
这个路径下,这个路径已经在我的系统环境变量中。当我运行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
2 个回答
我在使用 Python 3.9.12(Anaconda)时遇到了同样的问题。我在以下位置安装了 Visual C++ for Python:C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
然后我在这里找到了 msvc9compiler.py:
C:\Users\UserName\anaconda3\Lib\distutils,里面显示了
VS_BASE = r"Software\Microsoft\VisualStudio%0.1f"
请问如何将 vcvarsall.bat 指向 Python 呢?
(我已经添加了系统的 PATH,但完全没有效果。)C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
能不能告诉我如何在注册表中添加这个值?我在我的电脑上找不到 HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir。
我还是想知道在哪里设置对vsvarsall.bat的引用...
好吧,正如martineau所说,你需要安装Visual Studio 2008或者Visual C++ Express。说到这里,我明白你想知道Python会在哪里寻找这个批处理文件。你可以通过查看find_vcvarsall
函数在distutils/msvc9compiler.py这个标准模块中的定义来了解。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)。如果这些文件夹存在,Python就会把这些文件夹当作包含vcvarsall.bat
文件的文件夹。如果这些文件夹都不存在,Python会检查是否有环境变量VS90COMNTOOLS
。如果这个变量存在,Python会把这个变量值的上两层文件夹当作包含vcvarsall.bat
文件的文件夹。
另外,你可以看看我其他的回答,里面解释了为什么你不能用MSVC++ 2010来为Python 2.6构建扩展。
编辑:
VC++ 2008的文件现在已经打包成一个安装程序,可以从这里下载。安装后,vcvarsall.bat会在C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
这个路径下。