Open michaelsmolinski opened 5 months ago
The backend library fails to load because the precompiled header fails to build. I in particular note: error: Unsupported architecture
coming from the MSVC headers, which seems to suggest that there's a 64b <-> 32b mismatch. There seem to be headers loaded from C:\Program Files (x86)
, which suggests 32b, even as python looking for libcppyy_backend.cp312-win_amd64.pyd
suggests 64b.
How do you setup the MSVC environment? Additionally, which version of cppyy is this and how is it installed?
I believe the header (at least for that error) is coming from Windows SDK -- I think it installs both 64b and 32b to C:\Program Files (x86)
?
MSVC environment: Windows 11 Visual Studio Build Tools 2022 17.8.4 C++ MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) Windows SDK 10.0.22621.2428
Installed using pip install cppyy
- I'm assuming this is the latest release
If an alternative method to install would be better, let me know.
(please be patient as I'm not a C++ coder and relatively new to Python)
(please be patient as I'm not a C++ coder and relatively new to Python)
And I'm not a Windows user. :) I do builds through a VM.
But with "setup" I meant that you launch Python.exe from some environment. MSVC provides both 32b and 64b environments and unless Python was installed through VS, it could be mismatched. See e.g.: https://learn.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line?view=msvc-170
I believe it is normal for Windows SDK headers to reside in Program Files (x86)
even when building for x86-64. The C++ STL headers moved from Program Files (x86)
to Program Files
between VS 2019 and 2022, but the Windows SDK hasn't moved.
I get essentially the same error when running in Developer PowerShell for VS 2022.
pip cache purge
pip install cppyy
succeeds; no unusual messagespython
, import cppyy
Interestingly, I get no errors when doing the same in Developer PowerShell for VS 2019. My VS 2019 installation has the same 2 Windows 10 SDK versions installed, but not the Windows 11 SDK. So the problem may be specific to either VS2022 or Windows 11 SDK (or both).
I then upgraded VS2022 to 17.8.6 (but did not yet add Windows 11 SDK 10.0.22621.0). The same test produced the same errors.
Just for the heck of it, I uninstalled VS 2022's Windows 11 SDK (leaving only the Windows 10 SDKs listed above). Still got the same error.
So, at least at a coarse grain, the incompatibility seems to be with VS 2022 (or the Microsoft STL shipped with it).
Now if we look at the first error:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\\include\type_traits:1396:5: error: expected a type
_Copy_cv_impl<_From>::template _Apply<_To>;
^
I don't know how to find the exact commit in https://github.com/microsoft/STL for a given VS version (if there even is such a thing), but this is a case where they removed the typename
keyword (https://github.com/microsoft/STL/commit/f70d767e3b65e5d7084354b44c45499dde2f781c, Jul 2023). This error is part of a using
(type alias) definition and is within an #if _HAS_CXX20
. (This seems to have appeared in VS 2022 17.8 according to their changelog.)
I seem to recall that clang took some time to implement C++20 P0634 which made typename
optional in many places. According to the official status it was fully implemented in Clang 16.
If I understand correct that cppyy's backend (and Cling) is currently on LLVM 13, this could be the problem.
Based on this, if I set $Env:STDCXX='17'
(PowerShell syntax) before starting Python I can successfully import cppyy in Developer PowerShell for VS 2022 (17.8.6).
So until Cling and cppyy are rebased on a newer LLVM, we're probably limited on Windows to either disabling C++20 or sticking to a slightly older version of Visual Studio (2019, or some earlier version of 2022: maybe 17.7 but would need to be tested -- but no way to downgrade VS Community 2022).
Not to open a new issue: cannot install cppyy on Windows at all. Windows 10 Python 3.12 VS BuiltTools install with pip (cannot use conda) The error: error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\HostX86\x64\cl.exe' failed with exit code 2
The actual error should be printed above the error that you posted. If there's nothing there, add --verbose
to the pip
command. I can't do anything with, or recommend based on, the given information.
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\gni\AppData\Local\Temp\pip-build-env-yxozr3vc\overlay\Lib\site-packages\cppyy_backend\include -IC:\Users\gni\PycharmProjects\cppyyOCC\vEnv\include -IC:\Users\gni\AppData\Local\Python312\include -IC:\Users\gni\AppData\Local\Python312\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" /EHsc /Tpsrc\clingwrapper.cxx /Fobuild\temp.win-amd64-cpython-312\Release\src\clingwrapper.obj -O2 -Zc:__cplusplus /std:c++latest /GR /EHsc- /MD cl : Command line warning D9025 : overriding '/EHc' with '/EHc-' clingwrapper.cxx C:\Users\gni\AppData\Local\Temp\pip-install-yuzaamv1\cppyy-backend_332d819b74c14a1fb29f325fa09ec8fd\src\capi.h(4): fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
This is what printed above. Hope, it helps.
stddef.h
is a standard C header file that comes with the compiler. If the compiler can not find it, it's likely an environment setup or installation problem. Either way, it would be a local issue, so it's virtually impossible for me to figure out.
For the environment setup, check whether you're perhaps mixing 64b and 32b python and developer shell. For the installation, check the install options to see whether C/C++ headers and standard libs are installed.
Do I have to use MVSC on Windows or I can use MinGW as well? Looks like cppyy automatically looks for MVSC installation... I use virtual environment with system interpreter, I am sure it is 64b. BTW I use PyCharm, if it matters. I will try "verbose" option to see more...
I've never tried MinGW, but there are two pieces to it. The installation is done with pip
, which picks the compiler, not cppyy
. I can't really find much about it, other than out-of-date information. E.g. this info on python.org states that MinGW only works up to Python3.4. Other sources talk about a MinGW-specific pip
build. My guess is that it's not supported out-of-the-box. After that, once compilation has succeeded, the question is whether Clang finds the headers, but I presume that that at least can be ameliorated by setting the include paths.
Tried install/uninstall on Windows (x64) multiple times
Test code was 1 line: import cppyy
Here is the vscode output from the attempt:
terminal output: