admin管理员组

文章数量:1434363

I'm trying to use pybind for the first time. I tried different ways, but eventually I decided to go with the 'official' PyBind11 example.

I did the following steps:

  • install Visual Studio Build Tools 2022 (I choose Desktop development with C++)
  • launch "x64 Native Tools Command Prompt for VS 2022"
  • navigate to the directory where I have the Python venv created
  • activate venv
  • clone cmake_example from PyBind11: git clone --recursive .git
  • run: python ./cmake_example/setup.py install - finished successfully
  • run: python ./cmake_example/setup.py build finished successfully.

The last line printed by the script is: cmake_example.vcxproj -> D:\Git\pybindtest\build\lib.win-amd64-cpython-311\cmake_example.cp311-win_amd64.pyd, so I believe everything is built successfully.

However, when trying to run .\cmake_example\tests\test_basic.py, I'm getting a standard error:

Traceback (most recent call last):
  File "D:\Git\pybindtest\cmake_example\tests\test_basic.py", line 1, in <module>
    import cmake_example as m
ImportError: dynamic module does not define module export function (PyInit_cmake_example)

I got the same error when manually type import cmake_example in Python console.

本文标签: pythonBuilding pybind11 example successfullybut still got ImportErrorStack Overflow