Python pip install 出现错误:无法找到 vcvarsall.bat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19830942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pip install gives error: Unable to find vcvarsall.bat
提问by Nyxynyx
Using pip install zipline
on Windows 8 with Python 2.7 gives me the error:
使用pip install zipline
在Windows 8上使用Python 2.7给我的错误:
Downloading/unpacking six (from python-dateutil==2.1->delorean->zipline[all])
Running setup.py egg_info for package six
Installing collected packages: blist, pytz, requests, python-dateutil, six
Running setup.py install for blist
building '_blist' extension
error: Unable to find vcvarsall.bat
Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\users\ThatsMe\appdata\local\temp\pip-build-ThatsMe\blist\setup.py';ex
ec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" inst
all --record c:\users\ThatsMe\appdata\local\temp\pip-xvoky2-record\install-record.tx
t --single-version-externally-managed:
running install
running build
running build_py
running build_ext
building '_blist' extension
error: Unable to find vcvarsall.bat
Question:How can the error be resolved? Running pip install zipline[all]
gives the same error...
问题:如何解决错误?运行pip install zipline[all]
给出了同样的错误......
采纳答案by Kos
You could use ol' good easy_install zipline
instead.
你可以用 ol' goodeasy_install zipline
代替。
easy_install
isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.
easy_install
不是 pip,但它的一个好处是能够下载和安装二进制包,这将使您无需准备 VC++。这当然依赖于二进制文件是为您的 Python 版本准备的假设。
UPDATE:
更新:
Yes, Pip can install binaries now!
是的,Pip 现在可以安装二进制文件了!
There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip
. This means you'll be able to install zipline
with pip
without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.
有一种新的二进制 Python 存档格式 ( wheel) 应该替换“eggs”。轮子已经支持pip
。这意味着你将能够安装zipline
与pip
不尽快编译它有人建立了平台,并上传它的PyPI的车轮。
回答by Nitzan Shaked
You need to have Visual Studio's bin dir in your path. Pip install is trying to compile some C code.
您的路径中需要有 Visual Studio 的 bin 目录。Pip install 正在尝试编译一些 C 代码。
回答by Muhammad Soliman
Simply because you don't have c++ compiler installed there in your machine, check the following
仅仅因为您的机器中没有安装 c++ 编译器,请检查以下内容
Download Microsoft Visual C++ 2008 from this page. That is a generally useful page anyway, so you should probably bookmark it. For Python 3.3+ use MS Visual C++ 2010. Install it.
Open Windows explorer (the file browser) and search for the location of ‘vcvarsall.bat' and cut it to your clipboard.
run regedit from the Windows start key. You will need admin privilges.
Add a registry entry to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (64 bit Windows) or HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (32 bit) as described here.
从此页面下载 Microsoft Visual C++ 2008 。无论如何,这是一个通常有用的页面,因此您应该将其添加为书签。对于 Python 3.3+,请使用MS Visual C++ 2010。安装它。
打开 Windows 资源管理器(文件浏览器)并搜索“vcvarsall.bat”的位置并将其剪切到剪贴板。
从 Windows 开始键运行 regedit。您将需要管理员权限。
添加注册表项以9.0 \ SETUP \ VC \ ProductDir(64和Windows)或HKEY_LOCAL_MACHINE \ SOFTWARE \微软\ VisualStudio的\ 9.0 \ SETUP \ VC \ ProductDir(32位)所描述的HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \微软\ VisualStudio的\这里.
Hint: 0.9 in the registery directory is the currently installed version of your visual studio, if you running VS 2013, you have to find the path HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\12.0....
提示: registery 目录中的 0.9 是您当前安装的 Visual Studio 版本,如果您运行的是 VS 2013,则必须找到路径 HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\12.0....
At the Windows start key, type cmd to get a command shell. If you need to, go to your virtual environment and run activate.bat.
pip install or whatever you use to install it.
在 Windows 开始键处,键入 cmd 以获取命令外壳。如果需要,请转到您的虚拟环境并运行 activate.bat。
pip install 或任何你用来安装它的东西。
回答by Briksins
Thanks to "msoliman" for his hint, however his answer doesn't give clear solution for those who doesn't have VS2010
For example I have VS2012 and VS2013 and there are no such KEYs in system registry.
感谢“msoliman”的提示,但是他的回答并没有为那些没有 VS2010 的人提供明确的解决方案。
例如,我有 VS2012 和 VS2013,并且系统注册表中没有这样的 KEY。
Solution:
Edit file: "[Python_install_loc]/Lib/distutils/msvc9compiler.py"
Change on line 224:
解决方法:
编辑文件:“ [Python_install_loc]/Lib/distutils/msvc9compiler.py”
第224行修改:
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
"productdir")
to:
到:
productdir = "C:\Program Files (x86)\Microsoft Visual Studio [your_vs_version(11/12...)]\VC"
and that should work
这应该有效
回答by ismail
The problem here is the line 292 (Using Python 3.4.3 here) in $python_install_prefix/Lib/distutils/msvc9compiler.py
which says:
这里的问题是第 292 行(此处使用 Python 3.4.3),$python_install_prefix/Lib/distutils/msvc9compiler.py
其中说:
VERSION = get_build_version()
This only checks for the MSVC version that your python was built with. Just replacing this line with your actual Visual Studio version, eg. 12.0
for MSVC2013
这只会检查您的 Python 构建时使用的 MSVC 版本。只需用您的实际 Visual Studio 版本替换这一行,例如。12.0
为了MSVC2013
VERSION = 12.0
will fix the issue.
将解决问题。
UPDATE: Turns out that there is a good reason why this version is hardcoded. MSVC C runtime is not required to be compatible between major versions. Hence when you use a different VS version you might run into runtime problems. So I advise to use VS 2008 (for Python 2.6 up to 3.2) and VS2010 for (Python 3.3 and later) until this issue is sorted out.
更新:事实证明,这个版本被硬编码是有充分理由的。MSVC C 运行时不需要在主要版本之间兼容。因此,当您使用不同的 VS 版本时,您可能会遇到运行时问题。所以我建议使用 VS 2008(对于 Python 2.6 到 3.2)和 VS2010(对于 Python 3.3 及更高版本),直到这个问题得到解决。
Binary compatibility will arrive with VS 2015 (see here) along with Python 3.5 .
二进制兼容性将随 VS 2015(见此处)和 Python 3.5 一起出现。
For Python 2.7 users Microsoft released a special Microsoft Visual C++ Compiler for Python 2.7which can be used without installing the whole VS 2008.
对于 Python 2.7 用户,Microsoft 发布了一个特殊的Microsoft Visual C++ Compiler for Python 2.7,无需安装整个 VS 2008 即可使用。
回答by The Web Hive
If you are trying to install matplotlib in order to work with graphs on python. Try this link. https://github.com/jbmohler/matplotlib-winbuild. This is a set of scripts to build matplotlib from source on the MS Windows platform.
如果您尝试安装 matplotlib 以便在 python 上处理图形。试试这个链接。 https://github.com/jbmohler/matplotlib-winbuild。这是一组脚本,用于在 MS Windows 平台上从源代码构建 matplotlib。
To build & install matplotlib in your Python, do:
要在 Python 中构建和安装 matplotlib,请执行以下操作:
git clone https://github.com/matplotlib/matplotlib
git clone https://github.com/jbmohler/matplotlib-winbuild
$ python matplotlib-winbuild\buildall.py
The build script will auto-detect Python version & 32/64 bit automatically.
构建脚本将自动检测 Python 版本和 32/64 位。
回答by Miguel A. Sanchez-Perez
First, you should look for the file vcvarsall.bat in your system.
首先,您应该在系统中查找文件 vcvarsall.bat。
If it does not exist, I recommend you to install Microsoft Visual C++ Compiler for Python 2.7. This will create the vcvarsall.bat in "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0" if you install it for all users.
如果它不存在,我建议您安装Microsoft Visual C++ Compiler for Python 2.7。如果您为所有用户安装 vcvarsall.bat,这将在“C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0”中创建 vcvarsall.bat。
The problem now is in the function find_vcvarsall(version)in the C:/Python27/Lib/distutils/msvc9compiler.pymodule, which is looking for the vcvarsall.bat file.
现在的问题是在C:/Python27/Lib/distutils/msvc9compiler.py模块中的函数find_vcvarsall(version)中,它正在寻找 vcvarsall.bat 文件。
Following the function calls you will see it is looking for an entry in the registry containing the path to the vcvarsall.bat file. It will never find it because this function is looking in other directories different from where the above-mentioned installation placed it, and in my case, the registry didn't exist.
在函数调用之后,您将看到它正在注册表中查找包含 vcvarsall.bat 文件路径的条目。它永远不会找到它,因为此功能正在查找与上述安装位置不同的其他目录,而在我的情况下,注册表不存在。
The easiest way to solve this problem is to manually return the path of the vcvarsall.bat file. To do so, modify the function find_vcvarsall(version)in the msvc9compiler.pyfile with the absolute path to the vcvarsall.bat file like this:
解决这个问题最简单的方法是手动返回vcvarsall.bat文件的路径。为此,请使用vcvarsall.bat文件的绝对路径修改msvc9compiler.py文件中的函数 find_vcvarsall(version),如下所示:
def find_vcvarsall(version):
return r"C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python.0\vcvarsall.bat"
This solution worked for me.
这个解决方案对我有用。
If you already have the vcvarsall.bat file you should check if you have the key productdirin the registry:
如果您已经有了 vcvarsall.bat 文件,您应该检查注册表中是否有关键的productdir:
(HKEY_USERS, HKEY_CURRENT_USERS, HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC
(HKEY_USERS、HKEY_CURRENT_USERS、HKEY_LOCAL_MACHINE 或 HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC
Where version = msvc9compiler.get_build_version()
其中版本 = msvc9compiler.get_build_version()
If you don't have the key just do:
如果您没有密钥,请执行以下操作:
def find_vcvarsall(version):
return <path>\vcvarsall.bat
To understand the exact behavior check msvc9compiler.pymodule starting in the find_vcvarsall(version)function.
要了解从find_vcvarsall(version)函数开始的确切行为,请检查msvc9compiler.py模块。
回答by Broccoli Soup
If you are getting this error on Python 2.7 you can now get the Microsoft Visual C++ Compiler for Python 2.7as a stand alone download.
如果您在 Python 2.7 上遇到此错误,您现在可以单独下载Microsoft Visual C++ Compiler for Python 2.7。
If you are on 3.3 or later you need to install Visual Studio 2010 express which is available for free here: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express
如果您使用的是 3.3 或更高版本,则需要安装 Visual Studio 2010 express,可在此处免费获得:https: //www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express
If you are 3.3 or later and using a 64 bit version of python you need to install the Microsoft SDK 7.1 that ships a 64 bit compiler and follow the directions here Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7
如果您是 3.3 或更高版本并使用 64 位版本的 python,则需要安装附带 64 位编译器的 Microsoft SDK 7.1 并按照此处的说明进行操作在 Windows 7 上
回答by Philip Jones
I appreciate this might not be the answer to resolving on 3.4 but I tried a huge variety of things to fix this on 3.4 and thought this might be useful if someone is time pressed or doesn't have the know-how to correct it (in my case, work demands).
我很欣赏这可能不是解决 3.4 的答案,但我尝试了很多方法来解决 3.4 的问题,并认为如果有人时间紧迫或没有专业知识来纠正它(在我的情况,工作要求)。
With exactly the same setup, I found that my installation problems only happened with Python 3.4. When I changed to 2.7, all my issues seemed to be resolved.
使用完全相同的设置,我发现我的安装问题只发生在 Python 3.4 上。当我改成 2.7 时,我所有的问题似乎都解决了。
We have a rather overzealous security setup though so I'm going to try the same on my home version (still 3.4) and see if I have any more joy. My inclination is that my VS version has somehow been restricted and the answers above should help. If I find anything more tonight I'll add further detail.
我们有一个相当过分的安全设置,所以我将在我的家庭版本(仍然是 3.4)上尝试相同的设置,看看我是否有更多的乐趣。我的倾向是我的 VS 版本在某种程度上受到了限制,上面的答案应该会有所帮助。如果我今晚发现更多信息,我会添加更多细节。
This is my first reply, not the most technical I'm afraid!
这是我的第一个回复,恐怕不是技术含量最高的!
回答by ashishsingal
I spent hours researching this vcvarsall.bat as well. Most answers on SO focus on Python 2.7 and / or creating workarounds by modifying system paths. None worked for me. This solution worked out of the box for Python 3.5 and (I think) is the "correct" way of doing it.
我也花了几个小时研究这个 vcvarsall.bat。关于 SO 的大多数答案都集中在 Python 2.7 和/或通过修改系统路径来创建解决方法。没有一个对我有用。该解决方案适用于 Python 3.5,并且(我认为)是“正确”的做法。
See this link -- it describes the Windows Compilers to use for different versions of Python: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_standalone:_Visual_C.2B-.2B-_Build_Tools_2015_.28x86.2C_x64.2C_ARM.29
For Python 3.5, download this: https://www.microsoft.com/en-us/download/details.aspx?id=49983
For me, I had to run C:\Program Files (x86)\Microsoft Visual C++ Build Tools\Visual C++ x64 Native Build Tools Command Prompt for it to work. From that command prompt, I ran "pip install django_compressor" which was the particular package that was causing me an issue, and it worked perfectly.
请参阅此链接——它描述了用于不同版本 Python 的 Windows 编译器:https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_standalone: _Visual_C.2B-.2B- _Build_Tools_2015_.28x86.2C_x64.2C_ARM.29
对于 Python 3.5,请下载:https: //www.microsoft.com/en-us/download/details.aspx?id=49983
对我来说,我必须运行 C:\Program Files (x86)\Microsoft Visual C++ Build Tools\Visual C++ x64 Native Build Tools Command Prompt 才能让它工作。在该命令提示符下,我运行了“pip install django_compressor”,这是导致我出现问题的特定软件包,它运行良好。
Hope this saves someone some time!
希望这可以节省一些时间!