0

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.

Ayush
  • 457
  • 8
  • 16
  • 1
    Are there any other versions of python installed on your computer? – Marc Glisse May 22 '22 at 06:53
  • @MarcGlisse Yes, actually there are a lot of versions of Python installed and the default Python version is `Python 3.7.13`. However, `Python 3.8.10` is the Python version that I'm using in my virtualenv. – Ayush May 23 '22 at 03:23

1 Answers1

0

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.

Ayush
  • 457
  • 8
  • 16