'Installing wxPython on Windows: DistutilsPlatformError: Microsoft Visual C++ 14.2 or greater is required
I have installed:
- Python 3.10.1
- PyCharm Community 2021.3
- Visual Studio Build Tools 2022, including:
- C++ Build Tools Core Features
- C++ 2022 Redistributable Update
- C++ core desktop features
- MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
- Windows 10 SDK (10.0.19041.0)
- C++ CMake tools for Windows
- Testing tools core features - Build Tools
- C++ AddressSanitizer
- C++/CLI support for v143 build tools (Latest)
- C++ Modules for v143 build tools (x64/x86 - experimental)
When trying to install wxPython in my project's virtualenv, I get this error:
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.2 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
Both the error and anything I can find on the internet (including here) tells me to download C++ build tools and install C++ 14.2 or greater / the latest version. I have:
- done that (see the list above),
- rebooted
venv/Scripts/pip install --upgrade setuptoolsvenv/Scripts/pip install --upgrade wheelvenv/Scripts/pip install --upgrade pip
What am I missing here? Is there some sort of path variable that I need to configure somewhere so pip/wheel/setuptools knows where to find the compiler?
Solution 1:[1]
I have the same problem. Solved for me to use Python 3.9.9. Its maybe about a distutils problem in Python 3.10.1 with this warning from msvc9compiler.py:
DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12
This leads to:
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
Solution 2:[2]
The current wxPython 4.1.1 is not compatible with python 3.10 on windows (it works on Linux). You can download an older version of Visual Studio Build Tools to get around the issue with the DistutilsPlatformError, however you will not be able to successfully install on python 3.10 on windows. I found a solution for the problem, the link is Compile_wxPython_4.1.2a1_Python3.10_Windows. I was not able to compile it but there is a link to the whl file that was bult using the procedure. I downloaded and installed it using the command pip install wxPython-4.1.2a1-cp310-cp310-win_amd64.whl
I am confident in the near future 4.1.2 will be released to PyPy and you will be able to install it using pip.
Solution 3:[3]
This problem is currently being fixed. Or rather it is fixed and a PR will be made with the fix pretty soon. I wrote a proper MSVC build environment script instead of the one that comes with either distutils or setuptool neither of which really work correctly when setting up an MSVC build environment.
Here is a link to the script I wrote that handles setting up the build environment properly
https://github.com/kdschlosser/python_msvc
and here is a link to a working fork of wxPython
https://github.com/oleksis/Phoenix/tree/try-pyMSVC
The problem with wxPython compiling properly is because neither setuptools or distutils has the capability of detecting Visual Studio 2022 properly. My script uses COM interfaces to collect the information needed to set up the build environment. The environment is set up without using the vcvar*.bat files.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David M |
| Solution 2 | |
| Solution 3 | Kevin Schlossser |
