1

I realized a C++ project and I used pydbind11. All work fine on Linux (C++ compilation with CMake produces test executables and Python module that works when I import it, installation with pip install works too). On Windows, I compile the project with MSYS2 UCRT64 in a MSYS2 UCRT64 prompt. To launch .exe files, I need to launch them in a CMD prompt instead of a MSYS2 UCRT64 prompt, I don't know why. The compilation produces a .pyd file in build folder but I don't arrive to import it. I create a symreg folder at root project and I copy the .pyd file into with the appropriate DLL files. I try too with a __init__.py file with the following content:

from .symreg import *

Here is the output in MSYS2 UCRT64 prompt:

Julien@DESKTOP-0IQSQEO UCRT64 ~/symreg_ws/SymReg
$ ls symreg/
__init__.py       libblas.dll         libglog-2.dll    libstdc++-6.dll             zlib1.dll
__pycache__       libceres-4.dll      libgvc-6.dll     libwinpthread-1.dll
libarmadillo.dll  libgcc_s_seh-1.dll  libopenblas.dll  symreg.cp312-win_amd64.pyd

Julien@DESKTOP-0IQSQEO UCRT64 ~/symreg_ws/SymReg
$ python
Python 3.12.11 (main, Jun  7 2025, 12:31:34)  [GCC UCRT 15.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import symreg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:/Programmes/msys64/home/Julien/symreg_ws/SymReg/symreg/__init__.py", line 1, in <module>
    from .symreg import *
ModuleNotFoundError: No module named 'symreg.symreg'

Here is the output in CMD prompt:

D:\Programmes\msys64\home\Julien\symreg_ws\SymReg>D:\Programmes\msys64\ucrt64\bin\python.exe
Python 3.12.11 (main, Jun  7 2025, 12:31:34)  [GCC UCRT 15.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import symreg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Programmes\msys64\home\Julien\symreg_ws\SymReg\symreg\__init__.py", line 1, in <module>
    from .symreg import *
ModuleNotFoundError: No module named 'symreg.symreg'

For information, the project is here on GitHub with the MSYS2 commands to compile: https://github.com/Julien-Livet/SymReg.

I saw the gmpy2 package in site-packages folder and there is a .pyd file named gmpy2.cp312-mingw_x86_64_ucrt_gnu.pyd. I tried to rename my .pyd file with cp312-mingw_x86_64_ucrt_gnu.pyd extension but I obtained the following output:

>>> import symreg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:/Programmes/msys64/home/Julien/symreg_ws/SymReg/symreg/__init__.py", line 1, in <module>
    from .symreg import *
ImportError: DLL load failed while importing symreg: Le module spécifié est introuvable.

I added api-ms-win-crt-*.dll files. What it is strange is that it requires python312.dll whereas there is only libpython3.12.dll and libpython.dll in ucrt64/bin folder. I tried to put libpython3.12.dll by renaming it in python312.dll but when I try to import the module, I obtained a segmentation fault.

Have you any idea to use this .pyd file correctly? And then of course, install it to use it in Python scripts?

2
  • 1
    Have you tried running Process Monitor in the background while you run the program, then stop gathering ProcMon events (otherwise ProcMon becomes unuseable), and then filter for CreateFile calls by the python.exe executable to see which file it tries to load when attempting the import? Commented Jul 29 at 15:01
  • I tried Process Monitor and I saw CreateFile calls but nothing related to symreg. Commented Jul 31 at 17:48

1 Answer 1

0

I found the problem : in fact, CMake found the wrong Python interpreter, so I must specify the good one.

Sign up to request clarification or add additional context in comments.

2 Comments

Interestingly, what version of Python did CMake found in your case? Did you have many versions of Python in your MSYS2? I've repeated your instruction from github.com/Julien-Livet/SymReg "from scratch", and I was able to successfully build pyd and import symreg. The only Python interpreter in msys2/ucrt64 was Python 3.12.11 64 bit, the same as found by CMake: Found Python3: D:/msys2/ucrt64/bin/python (found version "3.12.11")
I have a Python interpreter here and it is this one that CMake found first in MSYS2 prompt: D:\Programmes\Python\Python312. I have only one version of Python in MSYS2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.