When working with development tools, especially Python-based packages that require compilation (like TensorFlow or OpenCV), you might encounter the error: “Microsoft Visual C++ 14.0 or greater is required“. This issue occurs because certain Python packages depend on Microsoft’s C++ Build Tools to compile source code on Windows systems. Without the required version of Microsoft Visual C++, these packages won’t install or run correctly.
This comprehensive guide will walk you through understanding the root cause of this error and provide detailed steps to install Microsoft Visual C++ 14.0 or a newer version to fix the issue.
What Is Microsoft Visual C++ 14.0?
Microsoft Visual C++ is a development environment used to create applications in the C++ programming language. Version 14.0 is part of Visual Studio 2015 and provides the necessary C++ build tools required by several Python packages to compile and run. Later versions of Visual C++ (like 14.1 or greater) are part of Visual Studio 2017, 2019, or 2022.
When the error says “Microsoft Visual C++ 14.0 or greater is required”, it’s typically indicating that your system lacks the necessary C++ compiler or build tools required to install and build specific Python modules.
Why This Error Occurs
This error usually happens when installing Python libraries or packages that rely on C++ for compilation. For example:
- Python packages like NumPy, SciPy, OpenCV, lxml, cryptography, and others often require Visual C++ Build Tools for installation.
- The Python package manager (pip) tries to compile parts of these packages during installation. If the correct version of Microsoft Visual C++ isn’t installed, the compilation fails, and the error appears.
How to Fix the Error: “Microsoft Visual C++ 14.0 or Greater Is Required”
To resolve this error, you need to install the Microsoft Visual C++ Build Tools. Below are the steps to install the necessary components and resolve the issue.
Step 1: Download and Install Microsoft Visual C++ Build Tools
- Visit the Official Microsoft Website:
- Go to the Microsoft Visual Studio download page: https://visualstudio.microsoft.com/visual-cpp-build-tools/.
- Download the Build Tools:
- On the page, you’ll find a button that says “Download Build Tools”. Click on it to download the installer.
- Run the Installer:
- Once the download is complete, run the Visual Studio Installer. You will be presented with several installation options.
- Select C++ Build Tools:
- In the installer, select the option for C++ build tools. This includes MSVC v14.x (the necessary compiler version), the Windows 10 SDK, and other tools needed to compile C++ projects.
Ensure that the following components are checked:
- MSVC v142 – VS 2019 C++ x64/x86 build tools.
- Windows 10 SDK (10.0.x.x).
- C++ CMake tools for Windows.
- Install the Tools:
- After selecting the necessary components, click Install to begin the installation process. This may take some time depending on your internet speed.
Step 2: Verify Installation
After the installation completes, you’ll want to verify that Microsoft Visual C++ is correctly installed.
- Open Command Prompt or PowerShell.
- Type the following command to ensure that the build tools are available:
cl
If the installation was successful, you should see information about the Microsoft C/C++ Compiler, confirming that the tools are correctly installed.
Step 3: Retry Installing the Python Package
Once Microsoft Visual C++ 14.0 or greater is installed, you can retry installing the Python package that previously failed.
- Open Command Prompt or PowerShell.
- Navigate to the directory where you want to install the package.
- Use pip to install the package again. For example, if you were trying to install lxml, use:
pip install lxml
This time, the installation should complete successfully without throwing the Microsoft Visual C++ 14.0 error.
Step 4: Installing Pre-Built Python Wheels (Optional)
If you’re unable to resolve the issue using the steps above, an alternative approach is to install pre-built Python wheels for the package. Pre-built wheels are binary distributions of Python packages that don’t require compilation, and therefore, bypass the need for Microsoft Visual C++.
- Visit the Unofficial Python Wheels website: https://www.lfd.uci.edu/~gohlke/pythonlibs/.
- Search for the package you want to install (e.g., lxml).
- Download the appropriate .whl file for your version of Python and system architecture (e.g., lxml‑4.x.x‑cp39‑cp39‑win_amd64.whl for Python 3.9 on 64-bit Windows).
- Use pip to install the wheel:
pip install path_to_downloaded_wheel
Step 5: Update Visual Studio or Build Tools (If Needed)
If you already have Microsoft Visual C++ 14.0 or higher installed, but you’re still seeing the error, it might be due to an outdated or incomplete installation. In this case, updating your build tools might resolve the issue.
- Open Visual Studio Installer (if you already have it installed).
- Under Installed products, locate Visual Studio Build Tools and click Modify.
- Ensure the required components (C++ build tools) are selected and up to date.
You can also download and install the latest Visual Studio Community Edition to ensure you have all the necessary tools for development.
Conclusion
The Microsoft Visual C++ 14.0 or greater is required error is a common issue encountered when installing certain Python packages that require C++ code compilation. By downloading and installing the Visual C++ Build Tools or using pre-built Python wheels, you can easily resolve this error and continue installing your packages without issue.
Keeping your development tools up-to-date and ensuring that the C++ build environment is properly configured is essential for a smooth Python development experience on Windows.