Python 3.8 不能与 Pybind11 一起导入 [Windows]

python 3.8 can't be imported with pybind11 [windows]

本文关键字:导入 Windows 一起 Pybind11 不能 Python      更新时间:2023-10-16

我正在使用pybind11在C++开发python库。问题是python 3.7/3.6运行良好,但是 无法导入 Python 3.8。这是导入库时的错误(假设库名称为 mylibrary(。

ImportError: DLL load failed while importing mylibrary: The specified module could not be found.

为什么 Python3.8 可以在 pybind11 中构建,但不能导入?

可能是你的C++ python 库本身依赖于共享库/DLL。Python 3.7/3.6 会在 PATH 或当前工作目录中搜索 DLL,但在 Python 3.8 中不再如此:

https://docs.python.org/3.8/whatsnew/3.8.html#ctypes

如果这是问题所在,您可以添加 using add_dll_directory(( 告诉 Python 3.8 应该在哪里查找 DLL。