pybind11 -Importerror:未定义的符号:_py_zerostruct

发布于 2025-01-31 06:46:34 字数 1638 浏览 2 评论 0 原文

我正在关注 pybind11 文档,并尝试为简单函数创建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

i获取 ImporterRor 未定义的符号:_PY_ZEROSTRUCT

我正在使用:

  • ubuntu ubuntu 20.04.4 lts
  • python Python 3.8.10
  • pip pip 20.0.2

我试图解决的问题

我研究了许多文章与同一错误有关,但实际上无法了解我将如何解决我的问题:

任何类型的帮助都将不胜感激。

I'm following the pybind11 documentation and trying to create Python bindings for a simple function Creating bindings for a simple function, but after compiling my C++ code with the following command:

g++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cc -o example$(python3-config --extension-suffix)

when I try to import the library in python using:

import example

I get an ImportError saying undefined symbol: _Py_ZeroStruct

I'm using:

  • Ubuntu : Ubuntu 20.04.4 LTS
  • Python : Python 3.8.10
  • Pip : Pip 20.0.2

What I tried to solve the issue

I looked into many articles related to the same error but couldn't really get an understanding of how I'm going to resolve my issue:

Any kind of help will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2025-02-07 06:46:34

好吧,在尝试了许多方法之后,我最终决定将 pybind11 作为我的项目中的子模型,并使用 python3.9 ,这次似乎可以使用。

任何遇到相同问题的人都可以尝试我的方法,它可能起作用,不要期望这个残酷的社区的帮助。

Well after trying a lot of methods I finally decided to add pybind11 as a submodule in my project and use Python3.9 and it seemed to work this time.

Anyone struggling with the same problem can try my method, it may work and don't expect help from this cruel community.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文