[Python] Import .pyd Python module

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    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'


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

    Continue reading...

Compartilhe esta Página