错误:运行 Python 脚本时需要 Microsoft Visual C++ 10.0(无法找到 vcvarsall.bat)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28251314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:59:40  来源:igfitidea点击:

Error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat) when running Python script

pythonnumpypycharm

提问by Richard Knife

Im trying to install numpy with PyCharm but i keep getting this error:

我正在尝试使用 PyCharm 安装 numpy,但我不断收到此错误:

error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).

错误:需要 Microsoft Visual C++ 10.0(无法找到 vcvarsall.bat)。

Can someone please explain to me exactly what i have to do to fix this error(and as simple and detailed as possible)? im using python 3.4.2 (i know this has been answered before but i did not understand it).

有人可以向我解释我必须做什么来修复这个错误(尽可能简单和详细)?我使用的是 python 3.4.2(我知道之前已经回答过这个问题,但我不明白)。

采纳答案by MasterAM

I got the same error and ended up using a pre-built distribution of numpy available in SourceForge(similarly, a distribution of matplotlibcan be obtained).

我遇到了同样的错误,最终使用了SourceForge 中可用的预构建 numpy 发行版 (同样,可以获得matplotlib的发行版)。

Builds for both 32-bit 2.7 and 3.3/3.4 are available.
PyCharm detected them straight away, of course.

32 位 2.7 和 3.3/3.4 的版本都可用。
当然,PyCharm 会立即检测到它们。

回答by Broccoli Soup

Python 3.3 and later now uses the 2010 compiler. To best way to solve the issue is to just install Visual C++ Express 2010for free.

Python 3.3 及更高版本现在使用 2010 编译器。解决此问题的最佳方法是免费安装Visual C++ Express 2010

Now comes the harder part for 64 bit users and to be honest I just moved to 32 bit but 2010 express doesn't come with a 64 bit compiler (you get a new error, ValueError: ['path'] ) so you have to install Microsoft SDK 7.1 and follow the directions here to get the 64 bit compiler working with python: Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7

现在是 64 位用户更难的部分,老实说我刚搬到 32 位,但 2010 express 没有配备 64 位编译器(你得到一个新错误, ValueError: ['path'] )所以你必须安装 Microsoft SDK 7.1 并按照此处的说明使 64 位编译器与 python 一起工作:Python PIP 有问题,MS Visual Studio 2010 Express 的路径在 Windows 7 上安装 64 位

It may just be easier for you to use the 32 bit version for now. In addition to getting the compiler working, you can bypass the need to compile many modules by getting the binary wheel file from this locaiton http://www.lfd.uci.edu/~gohlke/pythonlibs/

您现在可能更容易使用 32 位版本。除了让编译器工作之外,您还可以通过从此位置获取二进制轮文件来绕过编译许多模块的需要http://www.lfd.uci.edu/~gohlke/pythonlibs/

Just download the .whl file you need, shift + right click the download folder and select "open command window here" and run

只需下载您需要的 .whl 文件,shift + 右键单击​​下载文件夹并选择“在此处打开命令窗口”并运行

pip install module-name.whl 

I used that method on 64 bit 3.4.3 before I broke down and decided to just get a working compiler for pip compiles modules from source by default, which is why the binary wheel files work and having pip build from source doesn't.

在我崩溃之前,我在 64 位 3.4.3 上使用了这种方法,并决定只为 pip 获取一个工作编译器,默认情况下从源代码编译模块,这就是为什么二进制轮文件可以工作而从源代码构建 pip 没有的原因。

People getting this (vcvarsall.bat) error on Python 2.7 can instead install "Microsoft Visual C++ Compiler for Python 2.7"

在 Python 2.7 上收到此 (vcvarsall.bat) 错误的人可以安装“Microsoft Visual C++ Compiler for Python 2.7”

回答by Jiang Donghua

you can download .whl in LFD. Then use "pip install ***.whl" in CMD

您可以在LFD 中下载 .whl 。然后在 CMD 中使用“pip install ***.whl”

回答by Patrick

VS 2010 Express is no longer linked to any VS Express pages (that I found). I did find this link to the ISO which I used and it fixed the errors mentioned here.

VS 2010 Express 不再链接到任何 VS Express 页面(我发现)。我确实找到了指向我使用的 ISO 的链接,它修复了此处提到的错误。

http://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.iso

http://download.microsoft.com/download/1/E/5/1E5F1C0A-0D5B-426A-A603-1798B951DDAE/VS2010Express1.iso

Note: Also make sure you have x86 everything (Python + Postgresql) or you'll get other errors. I did not try x64 everything.

注意:还要确保你有 x86 的一切(Python + Postgresql),否则你会得到其他错误。我没有尝试 x64 的一切。

回答by Gordon Mckeown

I was able to fix this on Windows 7 64-bit running Python 3.4.3 by running the setcommand at a command prompt to determine the existing Visual Studio tools environment variable; in my case it was VS140COMNTOOLSfor Visual Studio Community 2015.

通过set在命令提示符下运行命令以确定现有的 Visual Studio 工具环境变量,我能够在运行 Python 3.4.3 的 Windows 7 64 位上修复此问题;就我而言,它VS140COMNTOOLS适用于 Visual Studio Community 2015。

Then run the following (substituting the variable on the right-hand side if yours has a different name):

然后运行以下命令(如果您的名称不同,则替换右侧的变量):

set VS100COMNTOOLS=%VS140COMNTOOLS%

This allowed me to install the PyCrypto module that was previously giving me the same error as the OP.

这使我能够安装 PyCrypto 模块,该模块以前给我与 OP 相同的错误。

For a more permanent solution, add this environment variable to your Windows environment via Control Panel ("Edit the system environment variables"), though you might need to use the actual path instead of the variable substitution.

要获得更持久的解决方案,请通过控制面板(“编辑系统环境变量”)将此环境变量添加到您的 Windows 环境中,但您可能需要使用实际路径而不是变量替换。

回答by FavorMylikes

I have encountered this problem twice. First time I used VS 2013 and the second time I used VS 2015 with different solution. The first solution on VS 2013 and python 2.7 is:

我遇到过两次这个问题。我第一次使用 VS 2013,第二次使用 VS 2015 和不同的解决方案。VS 2013 和 python 2.7 上的第一个解决方案是:

  1. Click win+R
  2. Enter SET VS90COMNTOOLS=%VS120COMNTOOLS%
  3. Close all windows
  4. Enter pip install again
  1. 点击win+R
  2. 进入 SET VS90COMNTOOLS=%VS120COMNTOOLS%
  3. 关闭所有窗口
  4. 再次输入pip install

Now, one year later, I have found an easier method to fix it. This time I use VS 2015 and python 3.4.

现在,一年后,我找到了一种更简单的方法来修复它。这次我使用 VS 2015 和 python 3.4。

  1. Right click on My Computer.
  2. Click Properties
  3. Advanced system settings
  4. Environment variables
  5. Add New system variable
  6. Enter VS100COMNTOOLSto the variable name
  7. Enter the value of VS140COMNTOOLSto the new variable.
  8. Close all windows
  1. 右键单击我的电脑。
  2. 单击属性
  3. 高级系统设置
  4. 环境变量
  5. 添加新的系统变量
  6. 输入VS100COMNTOOLS变量名
  7. 输入VS140COMNTOOLS新变量的值。
  8. 关闭所有窗口

Now I'm sure you will ask some question what is the VSXXXCOMNTOOLSand what should I do if I use VS2008 or other compiler.

现在我相信你会问一些问题,VSXXXCOMNTOOLS如果我使用 VS2008 或其他编译器,我应该怎么做。

There is a file python\Lib\distutils\msvc9compiler.py, beginning on line 216 we see

有一个文件python\Lib\distutils\msvc9compiler.py,从216行开始我们看到

def find_vcvarsall(version):
    """Find the vcvarsall.bat file
    At first it tries to find the productdir of VS 2010 in the registry. If
    that fails it falls back to the VS100COMNTOOLS env var.
    """

It means that you must give the productdir of VS 2010 for it, so if you are using python 2.x and

这意味着您必须为其提供 VS 2010 的 productdir,因此如果您使用的是 python 2.x 和

  • Visual Studio 2010 (VS10):SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11):SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12):SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS15):SET VS90COMNTOOLS=%VS140COMNTOOLS%
  • Visual Studio 2010 (VS10):SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11):SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12):SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS15):SET VS90COMNTOOLS=%VS140COMNTOOLS%

or if you are using python 3.x and

或者如果您使用的是 python 3.x 和

  • Visual Studio 2010 (VS10):SET VS100COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11):SET VS100COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12):SET VS100COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS15):SET VS100COMNTOOLS=%VS140COMNTOOLS%
  • Visual Studio 2010 (VS10):SET VS100COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11):SET VS100COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12):SET VS100COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS15):SET VS100COMNTOOLS=%VS140COMNTOOLS%

And it's the same as adding a new system variable. See the second ways.

和添加一个新的系统变量是一样的。参见第二种方式。

Update:Sometimes,it still doesn't work.Check your path,ensure that contains VSxxxCOMNTOOLS

更新:有时,它仍然不起作用。检查您的路径,确保包含 VSxxxCOMNTOOLS

回答by psych0

Tried to install lxml, grab and other extensions, which requires VS 10.0+ and get the same issue. I find own way to solve this problem(Windows 10 x64, Python 3.4+):

尝试安装 lxml、grab 和其他扩展,这需要 VS 10.0+ 并得到相同的问题。我找到自己的方法来解决这个问题(Windows 10 x64,Python 3.4+):

  1. Install Visual C++ 2010 Express (download). (Do not install Microsoft Visual Studio 2010 Service Pack 1 )

  2. Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.

  3. Install offline version of Windows SDK for Visual Studio 2010 (v7.1) (download). This is required for 64bit extensions. Windows has builtin mounting for ISOs. Just mount the ISO and run Setup\SDKSetup.exe instead of setup.exe.

  4. Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 that contains:

    CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

  5. Find extension on this site, then put them into the python folder, and install .whl extension with pip:

    python -m pip install extensionname.whl

  6. Enjoy

  1. 安装 Visual C++ 2010 Express(下载)。(不要安装 Microsoft Visual Studio 2010 Service Pack 1 )

  2. 从控制面板\程序和功能中删除所有 Microsoft Visual C++ 2010 Redistributable 包。如果你不这样做,那么安装将会失败,并出现一个模糊的“安装过程中的致命错误”错误。

  3. 安装适用于 Visual Studio 2010 (v7.1) 的离线版 Windows SDK(下载)。这是 64 位扩展所必需的。Windows 具有用于 ISO 的内置安装。只需挂载 ISO 并运行 Setup\SDKSetup.exe 而不是 setup.exe。

  4. 在 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 中创建一个 vcvars64.bat 文件,其中包含:

    调用“C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd”/x64

  5. 在本站找到扩展名,然后放入python文件夹,用pip安装.whl扩展名:

    python -m pip install extensionname.whl

  6. 享受

回答by AliSh

you have to check your pip package to be updated to the latest version in your pycharm and then install numpy package. in settings -> project:progLangComp -> Project Interpreter there is a table of packages and their current version (just labelled as Version) and their latest version (labelled as Latest). Pip current version number should be the same as latest version. If you see a blue arrow in front of pip, you have to update it to the latest then trying to install numpy or any other packages that you couldn't install, for me it was pandas which I wanted to install.

您必须在 pycharm 中检查要更新到最新版本的 pip 包,然后安装 numpy 包。在设置 -> 项目:progLangComp -> 项目解释器中有一个包表及其当前版本(仅标记为版本)和最新版本(标记为最新)。Pip 当前版本号应与最新版本相同。如果您在 pip 前面看到一个蓝色箭头,则必须将其更新为最新版本,然后尝试安装 numpy 或您无法安装的任何其他软件包,对我来说,我想安装的是 Pandas。

enter image description here

在此处输入图片说明