简体   繁体   English

运行 Python 脚本时找不到 vcvarsall.bat

[英]Cannot find vcvarsall.bat when running a Python script

I am working on Vista, and using Python 2.6.4.我在 Vista 上工作,使用 Python 2.6.4。 I am using a software that utilizes a Python script, but bumped into the message:我正在使用一个利用 Python 脚本的软件,但遇到了以下消息:

cannot find vcvarsall.bat

So, I installed visual c++ 2010. Still the file is not found - though, it is there.所以,我安装了visual c++ 2010。仍然没有找到该文件——尽管它在那里。 My guess (a very uneducated one...) is that somewhere the path is wrong, because I also have an old visual 2008 (pretty empty) folder.我的猜测(一个非常没有受过教育的人......)是路径错误的某个地方,因为我还有一个旧的视觉 2008(非常空)文件夹。 I have no idea where to make the changes for the new path.我不知道在哪里对新路径进行更改。 Do I change something in the registry or in the script?我是否更改了注册表或脚本中的某些内容? Or somewhere else?或者别的地方?

It seems that Python is looking explicitly for Visual Studio 2008. I encountered this problem where it couldn't find vcvarsall.bat even though it was on the path.似乎 Python 正在明确寻找 Visual Studio 2008。我遇到了这个问题,即使它在路径上也找不到 vcvarsall.bat。

It turns out that Visual Studio 2010 creates the following environment variable:事实证明,Visual Studio 2010 创建了以下环境变量:

SET VS100COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\

The fix is to create a variable called VS90COMNTOOLS and have that point to your Visual Studio 2010 common tools folder, eg修复方法是创建一个名为VS90COMNTOOLS的变量, VS90COMNTOOLS该变量指向您的 Visual Studio 2010 通用工具文件夹,例如

SET VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\

That fixed it for me and I can now build packages using the Visual Studio 2010 compiler.这为我修复了它,我现在可以使用 Visual Studio 2010 编译器构建包。

You can also set the VS90 environment variable to point to the VS100 environment variable using the command below:您还可以使用以下命令将 VS90 环境变量设置为指向 VS100 环境变量:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

Here's a simple solution .这是一个简单的解决方案 I'm using Python 2.7 and Windows 7.我正在使用 Python 2.7 和 Windows 7。

What you're trying to install requires a C/C++ compiler but Python isn't finding it.您尝试安装的内容需要 C/C++ 编译器,但 Python 找不到它。 A lot of Python packages are actually written in C/C++ and need to be compiled.很多Python包实际上是用C/C++编写的,需要编译。 vcvarsall.bat is needed to compile C++ and pip is assuming your machine can do that.需要 vcvarsall.bat 来编译 C++ 并且 pip 假设您的机器可以做到这一点。

  1. Try upgrading setuptools first, because v6.0 and above will automatically detect a compiler.首先尝试升级 setuptools,因为 v6.0 及以上版本会自动检测编译器。 You might already have a compiler but Python can't find it.您可能已经有一个编译器,但 Python 找不到它。 Open up a command line and type:打开命令行并输入:

    pip install --upgrade setuptools

  2. Now try and install your package again:现在尝试再次安装您的软件包:

    pip install [yourpackagename]

  3. If that didn't work, then it's certain you don't have a compiler, so you'll need to install one:如果这不起作用,那么可以肯定您没有编译器,因此您需要安装一个:
    http://www.microsoft.com/en-us/download/details.aspx?id=44266 http://www.microsoft.com/en-us/download/details.aspx?id=44266

  4. Now try again:现在再试一次:

    pip install [yourpackagename]

And there you go.你去吧。 It should work for you.它应该适合你。

The solution to this problem is to set the following environment variable:解决这个问题的方法是设置以下环境变量:

VS90COMNTOOLS

For instance:例如:

set VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools

This error can be caused by not rebooting after installing Visual Studios, or not starting a new command prompt after installing.此错误可能是由于安装 Visual Studios 后未重新启动,或安装后未启动新的命令提示符所致。

Also the version of Visual Studios you can use to compile the extensions may depend on the version of python you are building for.此外,可用于编译扩展的 Visual Studios 版本可能取决于您正在构建的 Python 版本。

In 2015 , if you still getting this confusing error, blame python default setuptools that PIP uses.2015 年,如果您仍然遇到这个令人困惑的错误,请归咎于PIP 使用的python 默认设置工具

  1. Download and install minimal Microsoft Visual C++ Compiler for Python 2.7 required to compile python 2.7 modules from http://www.microsoft.com/en-in/download/details.aspx?id=44266http://www.microsoft.com/en-in/download/details.aspx?id=44266下载并安装编译 python 2.7 模块所需的最小Microsoft Visual C++ Compiler for Python 2.7
  2. Update your setuptools - pip install -U setuptools更新您的 setuptools - pip install -U setuptools
  3. Install whatever python package you want that require C compilation.安装任何需要 C 编译的 python 包。 pip install blahblah

It will work fine.它会正常工作。

UPDATE : It won't work fine for all libraries.更新:它不适用于所有图书馆。 I still get some error with few modules, that require lib-headers.我仍然遇到一些需要lib-headers的模块的错误。 They only thing that work flawlessly is Linux platform他们唯一完美运行的就是 Linux 平台

This cryptic error means that you don't have a C compiler installed.这个神秘的错误意味着您没有安装 C 编译器。 There was a discussion to propose a more explanative error (which is continued here , register and comment if you care about it!) but currently it is still not implemented.有一个讨论提出了一个更具解释性的错误在这里继续,如果你关心它,注册和评论!)但目前它仍然没有实现。

To fix this issue you can either install the Visual Studio 2008 SDK which will take about a GB, or you can install the very small VCForPython27.msi but which is not well supported by distutils currently, here's the procedure:要解决此问题,您可以安装大约需要 1 GB 的 Visual Studio 2008 SDK,或者您可以安装非常小的 VCForPython27.msi,但目前 distutils 不支持它,步骤如下:

1) install Microsoft Visual C++ Compiler for Python 2.7 from
http://www.microsoft.com/en-us/download/details.aspx?id=44266
2) Enter MSVC for Python command prompt
3) SET DISTUTILS_USE_SDK=1
4) SET MSSdk=1
5) you can then build your C extensions: python.exe setup.py ...

Steps 2 to 4 must be reproduced everytime before building your C extensions.每次构建 C 扩展之前,都必须重复步骤 2 到 4。 This is because of an issue with the VCForPython27.msi which install the header files and vcvarsall.bat in folders of a different layout than the VS2008 SDK and thus confuse the compiler detection of distutils.这是因为 VCForPython27.msi 存在问题,该文件将头文件和 vcvarsall.bat 安装在与 VS2008 SDK 布局不同的文件夹中,从而混淆了 distutils 的编译器检测。 This will get fixed in setuptools in Python 2.7.10.这将在 Python 2.7.10 的 setuptools 中得到修复。

Bug report and workaround by Gregory Szorc: http://bugs.python.org/issue23246 Gregory Szorc 的错误报告和解决方法: http ://bugs.python.org/issue23246

More info and a workaround for using %%cython magic inside IPython:https://github.com/cython/cython/wiki/CythonExtensionsOnWindows在 IPython 中使用 %%cython 魔法的更多信息和解决方法:https ://github.com/cython/cython/wiki/CythonExtensionsOnWindows

/EDIT: Also, if you have another version of Python, you cannot use Microsoft Visual C++ for Python 2.7, which is a kind of mini-compiler specifically made by Microsoft for Python 2.7. /编辑:另外,如果你有另一个版本的 Python,你不能使用 Microsoft Visual C++ for Python 2.7,它是一种由 Microsoft 专门为 Python 2.7 制作的迷你编译器。 In this case, you need to install the Visual Studio SDK that match your Python version, or a Windows SDK with the correct NET framework version.在这种情况下,您需要安装与您的 Python 版本匹配的 Visual Studio SDK,或具有正确 NET 框架版本的 Windows SDK。 See here for more infos: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows#using-windows-sdk-cc-compiler-works-for-all-python-versions有关更多信息,请参见此处: https : //github.com/cython/cython/wiki/CythonExtensionsOnWindows#using-windows-sdk-cc-compiler-works-for-all-python-versions

this worked for me (python 2.6):这对我有用(python 2.6):

installed free ms visual studio 2008 from http://www.microsoft.com/visualstudio/en-us/products/2008-editions/expresshttp://www.microsoft.com/visualstudio/en-us/products/2008-editions/express安装了free ms visual studio 2008

copied vcvarsall.bat from "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC>" to "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\Tools\\"vcvarsall.bat"C:\\Program Files\\Microsoft Visual Studio 9.0\\VC>"复制到"C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\Tools\\"

the installer had already set this environment variable:安装程序已经设置了这个环境变量:

VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\

Looks like MS has released the exact package needed here .看起来 MS 已经在 这里发布了所需的确切包。 BurnBit here . BurnBit在这里 Install it and then set the registry keys in this answer to point to C:\\Users\\username\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0安装它,然后将此答案中的注册表项设置为指向C:\\Users\\username\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0

Installing Visual C++ is a good first step, though I couldn't say for sure whether the 2010 version will work.安装 Visual C++ 是一个很好的第一步,虽然我不能肯定2010 版本是否可以工作。 Anyway give it a try.无论如何试一试。

Look for vcvarsall.bat in the Visual C++ installation directory (for Visual Studio 2010 it's in ProgramFiles\\Microsoft Visual Studio 10.0\\VC ).在 Visual C++ 安装目录中查找vcvarsall.bat (对于 Visual Studio 2010,它位于ProgramFiles\\Microsoft Visual Studio 10.0\\VC )。 Then add that directory to the system path.然后将该目录添加到系统路径。 If you're doing this on the command line, you can try:如果您在命令行上执行此操作,则可以尝试:

path %path%;c:\path\to\vs2010\bin

then try again to run whatever you were trying to run.然后再次尝试运行您尝试运行的任何内容。

For more permanent effect, add it in the computer system path settings .如需更持久的效果, 请将其添加到计算机系统路径设置中

If you had installed Visual studio 2015 by the quick install, vcvarsall.bat is not there.如果您通过快速安装安装了 Visual Studio 2015,则 vcvarsall.bat 不存在。 But you can go to programm and fonctionalities, and modify the installation in order to install c++ tools, then vcvarsall.bat will be present.但是你可以去programm and fonctionalities,修改安装以便安装c++工具,那么vcvarsall.bat就会出现了。

THIS IS AN UP TO DATE ANSWER FOR WINDOWS USERS - VERY SIMPLE SOLUTION.这是 WINDOWS 用户的最新答案 - 非常简单的解决方案。

As pointed out by other, the problem is that python/cython etc. tries to find the same compiler they were built from, but this compiler does not exist on the computer.正如其他人所指出的那样,问题在于 python/cython 等试图找到构建它们的相同编译器,但该编译器在计算机上不存在。 Most of the time, this compiler is a version of visual studio (2008, 2010 or 2013), but either such a compiler is not installed, or a newer version is installed and the system prevents from installing an older one.大多数情况下,此编译器是 Visual Studio 的一个版本(2008、2010 或 2013),但要么未安装此类编译器,要么安装了较新版本且系统阻止安装较旧版本。 So, the solution is simple:所以,解决方法很简单:

1) look at C:\\Program Files (x86) and see if there is an installed version of Microsoft visual studio, and if it is newer than the version from which Python has been built. 1) 查看 C:\\Program Files (x86) 并查看是否安装了 Microsoft Visual Studio 的版本,以及它是否比构建 Python 的版本更新。 If not, install(/update to) the version from which Python has been built (see previous answers), or even a newest version and follow the next step.如果没有,请安装(/更新到)构建 Python 的版本(参见之前的答案),甚至是最新版本,然后按照下一步操作。

2)If a newest version of Microsoft visual studio is already installed, we have to make Python/cython etc. believe that it is the version from which it has been built. 2)如果已经安装了最新版本的 Microsoft Visual Studio,我们必须让 Python/cython 等相信它是构建它的版本。 And this is very simple: go to the the system environment variables and create the following variables, if they do not exist:这很简单:转到系统环境变量并创建以下变量,如果它们不存在:

VS100COMNTOOLS VS100COMTOOLS

VS110COMNTOOLS VS110COMTOOLS

VS120COMNTOOLS VS120COMTOOLS

VS140COMNTOOLS VS140COMTOOLS

And set the field of these variables to并将这些变量的字段设置为

"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools" (if visual studio 2008 is installed), or "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools" (if visual studio 2010 is installed) or "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools" (if visual studio 2013 is installed) or "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools" (if visual studio 2015 is installed). “C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools”(如果安装了 Visual Studio 2008),或“C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools”(如果Visual Studio 2010 已安装)或“C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools”(如果安装了 Visual Studio 2013)或“C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\ Common7\\Tools”(如果安装了 Visual Studio 2015)。

This solution works for 32 bit versions of python.此解决方案适用于 32 位版本的 python。 It may also work for 64 bit version but I've not tested;它也可能适用于 64 位版本,但我没有测试过; most probably, for 64 bit versions, the following additional steps must be performed:很可能,对于 64 位版本,必须执行以下附加步骤:

3)add the path "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC" to the %PATH% environment variable (change the number of the version of visual studio according to you version). 3)在%PATH%环境变量中添加路径“C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC”(根据你的版本改变visual studio的版本号)。

4) from the command line, run "vcvarsall.bat x86_amd64" 4) 从命令行,运行“vcvarsall.bat x86_amd64”

That's all.就这样。

After trying every option available on every thread, I decided to dig into the source to find a solution.在尝试了每个线程上可用的每个选项后,我决定深入研究源以找到解决方案。

Edit your $PythonPath/Lib/distutils/_msvccompiler.py编辑你的$PythonPath/Lib/distutils/_msvccompiler.py

Find def _find_vcvarsall(plat_spec): Add as the next line, add find def _find_vcvarsall(plat_spec):添加为下一行,添加

    PathToVC=r"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
    return PathToVC, r""

And then make sure your visual studio bin directory is in your path.然后确保您的 Visual Studio bin 目录在您的路径中。

If this doesn't work, there are other files you may need to edit including:如果这不起作用,您可能需要编辑其他文件,包括:

  • $PythonPath/Lib/distutils/msvc9compiler.py $PythonPath/Lib/distutils/msvc9compiler.py
  • $PythonPath/Lib/site-packages/setuptools/msvc9_support.py $PythonPath/Lib/site-packages/setuptools/msvc9_support.py

I tried the solution here to set an environment variable via the command line, but this didn't work.我在这里尝试了通过命令行设置环境变量的解决方案,但这不起作用。 I did this both from a regular command prompt and from the Visual Studio Developer command prompt.我从常规命令提示符和 Visual Studio Developer 命令提示符执行此操作。

I could overcome this problem like this:我可以像这样克服这个问题:

  1. go to the Environment variables screen and created a new variable there VS100COMNTOOLS and let it point to my Visual Studio installation folder C:\\Program Files\\Microsoft Visual Studio 12.0\\Common7\\Tools\\转到环境变量屏幕并在 VS100COMNTOOLS 处创建一个新变量并让它指向我的 Visual Studio 安装文件夹 C:\\Program Files\\Microsoft Visual Studio 12.0\\Common7\\Tools\\
  2. Go to the above folder.转到上面的文件夹。 Inside this folder there is the file vsvars32.bat.在这个文件夹中有文件 vsvars32.bat。 Copy this file and rename it to vsvarsall.bat复制此文件并将其重命名为 vsvarsall.bat

My configuration is Visual Studio 2013 (12.0) and Python 3.4.2我的配置是 Visual Studio 2013 (12.0) 和 Python 3.4.2

Note that there is a very simple solution.请注意,有一个非常简单的解决方案。

  1. Download the software from http://www.microsoft.com/en-us/download/details.aspx?id=44266 and install it.http://www.microsoft.com/en-us/download/details.aspx?id=44266下载软件并安装。

  2. Find the installing directory, it is something like "C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python"找到安装目录,类似于“C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python”

  3. Change the directory name "C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0" to "C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\VC"将目录名称“C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0”更改为“C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++”用于 Python\\VC”

  4. Add a new environment variable "VS90COMNTOOLS" and its value is "C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\VC\\VC"添加新的环境变量“VS90COMNTOOLS”,其值为“C:\\Users\\USER_NAME\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\VC\\VC”

Now everything is OK.现在一切正常。

In case anyone comes here looking for an answer for Python 3.5;如果有人来这里寻找 Python 3.5 的答案; you need Visual Studio 2015.您需要 Visual Studio 2015。

Get Visual Studio 2015 Community here: https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx , this worked for me with no further steps needed.在此处获取 Visual Studio 2015 社区: https : //www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx ,这对我有用,不需要进一步的步骤。

Many thanks to Ionel, apparently the only place on the web to find this information!非常感谢 Ionel,显然是网络上唯一可以找到此信息的地方! http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/ http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/

Install Visual Studio Express 2008 (9.0) from here: http://go.microsoft.com/?linkid=7729279从这里安装 Visual Studio Express 2008 (9.0): http : //go.microsoft.com/?linkid=7729279

That's what fixed it for me.这就是为我修复它的原因。

After installation of Visual Studio Community 2015 Edition on Windows 10 64 bit.在 Windows 10 64 位上安装 Visual Studio Community 2015 版后。 This error did not go.这个错误没有去。 Then I install Microsoft Visual C++ Compiler for Python 2.7 .然后我安装Microsoft Visual C++ Compiler for Python 2.7 Since it requires vcvarsall.bat file.因为它需要vcvarsall.bat文件。 This file is no where in Visual studio Community 2015, but it was in Microsoft Visual C++ Compiler for Python 2.7.这个文件在 Visual Studio Community 2015 中没有,但它在 Microsoft Visual C++ Compiler for Python 2.7 中。 I also added its path into my environment variables but it also did not work.我还将其路径添加到我的环境变量中,但它也不起作用。 Then I un-install python 3.4.2 and deleted all the folders of python, and installed python 2.7.然后我卸载python 3.4.2并删除python的所有文件夹,并安装python 2.7。 Finally I run pip using powershell and I was able to install my required package ie flask-user, by using.最后,我使用 powershell 运行 pip,并且能够通过使用安装所需的软件包,即烧瓶用户。

pip install flask-user

There is a confusing edge case for this on windows.在 Windows 上有一个令人困惑的边缘情况。 If you follow the advice to install the 2007 windows, and you still get this error when doing python setup.py install directly, then it may be that the setup.py uses the old version of set up tools.如果按照建议安装2007 windows,直接执行python setup.py install还是出现这个错误,可能是setup.py使用了老版本的安装工具。

In particular, the code that points windows towards the right location for the windows installed compiler is in the __init__ method of the setuptools library, which means that you must in your setup.py use the setuptools module.特别是,将 windows 指向安装了 windows 的编译器的正确位置的代码位于 setuptools 库的__init__方法中,这意味着您必须在 setup.py 中使用 setuptools 模块。 Some older setup.py call methods directly from distutils.core .一些旧的 setup.py 直接从distutils.core调用方法。 If this is the case then the setup.py will never find the windows installed compiler.如果是这种情况,则 setup.py 将永远找不到 Windows 安装的编译器。 This can be fixed by simply writing import setuptools as the first line of the setup.py file.这可以通过简单地将 import setuptools 写为 setup.py 文件的第一行来解决。

Reference: https://bugs.python.org/issue23246 : Look about half way down for the quote from steve dower:参考:https ://bugs.python.org/issue23246 :从 steve dower 的引文往下看大约一半:

Setuptools has the code to find the compiler package. Setuptools 具有查找编译器包的代码。 We deliberately put it there instead of in distutils to make sure more people would get it.我们特意把它放在那里而不是放在 distutils 中,以确保更多的人会得到它。 I should probably port the extra check into 2.7.10, but the immediate fix is to import setuptools.我可能应该将额外的检查移植到 2.7.10,但直接的解决方法是导入 setuptools。

I was getting also this error error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).我也收到此错误错误:需要 Microsoft Visual C++ 10.0(无法找到 vcvarsall.bat)。

I used .whl file for installation.我使用 .whl 文件进行安装。

C:\Users\Python\Python34\Scripts>pip install C:\Users\Downloads\Cython-0.28-cp34-cp34m-win_amd64.whl

Cython-0.28-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform. Cython-0.28-cp34-cp34m-win_amd64.whl 在此平台上不受支持。

rename cp34m to none in .whl file and then try.在 .whl 文件中将 cp34m 重命名为none然后尝试。

C:\Users\Python\Python34\Scripts>pip install C:\Users\Downloads\Cython-0.28-cp34-none-win_amd64.whl

Processing c:\\users\\downloads\\cython-0.28-cp34-none-win_amd64.whl处理 c:\\users\\downloads\\cython-0.28-cp34-none-win_amd64.whl

Installing collected packages: Cython安装收集的软件包:Cython

Successfully installed Cython-0.28成功安装 Cython-0.28

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM