在安装 Python 包时,如何解决“错误: 需要 Microsoft Visual C + + 14.0或更高版本”?

我试图在 Python 上安装一个软件包,但是 Python 在安装软件包时抛出了一个错误。每次尝试安装 pip install google-search-api都会出错。

这里有一个错误,我如何才能成功地安装它?

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

我已经更新了它,并且有了14.27的最新版本,但问题是抛出了相同的错误。

170581 次浏览

Go to this link and download Microsoft C++ Build Tools:
https://visualstudio.microsoft.com/visual-cpp-build-tools/

enter image description here

Open the installer, then follow the steps.

You might have something like this, just download it or resume.

MSBT

If updating above doesn't work then you need to configure or make some updates here. You can make some updates here too by clicking "Modify".

Check that and download what you need there or you might find that you just need to update Microsoft Visual C++ as stated on the error, but I also suggest updating everything there because you might still need it on your future programs. I think those with the C++ as I've done that before and had a similar problem just like that when installing a python package for creating WorldCloud visualization.

C++ Build tools


UPDATE: December 28, 2020

You can also follow these steps here:

  1. Select: Workloads → Desktop development with C++
  2. Then for Individual Components, select only:
    • Windows 10 SDK
    • C++ x64/x86 build tools

You can also achieve the same automatically using the following command:

vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools

Reference:
https://www.scivision.dev/python-windows-visual-c-14-required

2020 - redist/build tools for Visual C++

silent installs can be done using the following two commands :

vs_buildtools__370953915.1537938681.exe --quiet --add Microsoft.VisualStudio.Workload.VCTools

and

VC_redist.x64.exe  /q /norestart
  1. Upgrade your pip with: python -m pip install --upgrade pip

  2. Upgrade your wheel with: pip install --upgrade wheel

  3. Upgrade your setuptools with: pip install --upgrade setuptools

  4. close the terminal

  5. try installing the pacakage again.

Boom !!! it works.

Tried Prason's approach. Also tried the fix suggested here

  1. conda install -c conda-forge implicit
  2. pip install --upgrade gensim

check if no older version of Microsoft Visual C++ are installed. If so uninstall them.

I tried everything and then finally, downgrading from python 3.10 to 3.9 is what worked. (I noticed it in this comment, but it is a bit different scenario: https://stackoverflow.com/a/70617749/17664284 )

I encounered the above-mentionned problem when using virtualenv. Using conda environment instead solved the problem. Conda automatically installs vs2015_runtime which compiles the wheels with no problem.

In addition to the verified answer by @ice bear, just make sure to reboot your system after downloading and installing the latest visual studio build tools. And then the error you might be getting would go!

  1. here is my error ERROR: Could not build wheels for multidict, which is required to install pyproject.toml-based projects enter image description here

  2. download whl https://www.lfd.uci.edu/~gohlke/pythonlibs/#multidict

enter image description here

  1. pip install multidict-6.0.2-py3-none-any.whl

  2. pip install httpie