最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - Building pybind11 example successfully, but still got ImportError - Stack Overflow

matteradmin5PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far