【发布时间】:2022-06-22 18:32:47
【问题描述】:
我正在关注pybind11 文档并尝试为一个简单的函数Creating bindings for a simple function 创建 Python 绑定,但是在使用以下命令编译了我的 C++ 代码之后:
g++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cc -o example$(python3-config --extension-suffix)
当我尝试在 python 中导入库时:
import example
我收到一个ImportError 说undefined symbol: _Py_ZeroStruct
我正在使用:
-
Ubuntu:
Ubuntu 20.04.4 LTS -
Python:
Python 3.8.10 -
点:
Pip 20.0.2
我试图解决的问题
我查看了许多与同一错误相关的文章,但无法真正了解我将如何解决我的问题:
- Python3.5 incompatibility: undefined symbol
- ImportError: undefined symbol: _Py_ZeroStruct
- undefined symbol using pybind11 cmd
- Undefined Symbol error when linking pybind11 with a dynamic library that calls an external function
我们将不胜感激任何形式的帮助。
【问题讨论】:
-
你的电脑上是否安装了其他版本的python?
-
@MarcGlisse 是的,实际上安装了很多 Python 版本,默认 Python 版本是
Python 3.7.13。但是,Python 3.8.10是我在 virtualenv 中使用的 Python 版本。
标签: python c++ ubuntu pybind11