最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论