On Windows, the debug python (
python_d) is not compatible with release-python modules (see below).
This rises from inconvenient to problematic because of pyconfig.h on windows, which uses
#pragma comments to inject library dependencies into the executable.
It does so with no opt-out, though: cpython/pyconfig.h at 3.10 · python/cpython (github.com)
# if defined(_DEBUG) # pragma comment(lib,"python310_d.lib")
There really should be some kind of opt-out around this so that people don’t have to (know to) vendor their python 3 just to not have the wrong libraries forcibly linked on them from a header file…
I get that there can be complications when linking debug/release binaries, esp with shared libraries/dlls and especially on windows, but it wasn’t the immovable object in Python 2.7 that it now seems to be in Py 3.
Looking at various build/ci systems, it really seems like Python 3 is presumed to handle Windows like a second-class citizen at the moment (c.f cmake’s find_python has some horrible hacks to handle windows-python).
Does the project not have a Windows champion?
# module-incompatibility between release- and debug- python on Windows # aka your life will suck if you embed python and want to switch from debug/release [C:\temp] > rm -rec -for .venv310 && C:\Python310\python -m venv .venv310 && . ./.venv310/scripts/activate.ps1 (.venv310) [C:\temp] > python -m pip install -q psutil numpy # release python WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available. You should consider upgrading via the 'C:\temp\.venv310\Scripts\python.exe -m pip install --upgrade pip' command. (.venv310) [C:\temp] > python # release python Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy, psutil >>> exit() (.venv310) [C:\temp] > python_d # debug python Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 18:46:13) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy Traceback (most recent call last): File "C:\temp\.venv310\lib\site-packages\numpy\core\__init__.py", line 22, in <module> from . import multiarray File "C:\temp\.venv310\lib\site-packages\numpy\core\multiarray.py", line 12, in <module> from . import overrides File "C:\temp\.venv310\lib\site-packages\numpy\core\overrides.py", line 7, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\temp\.venv310\lib\site-packages\numpy\__init__.py", line 150, in <module> from . import core File "C:\temp\.venv310\lib\site-packages\numpy\core\__init__.py", line 48, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.10 from "C:\temp\.venv310\Scripts\python_d.exe" * The NumPy version is: "1.21.4" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No module named 'numpy.core._multiarray_umath' >>> import psutil Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\temp\.venv310\lib\site-packages\psutil\__init__.py", line 107, in <module> from . import _pswindows as _psplatform File "C:\temp\.venv310\lib\site-packages\psutil\_pswindows.py", line 35, in <module> from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS ModuleNotFoundError: No module named 'psutil._psutil_windows'