pybind / python_example

Example pybind11 module built with a Python-based build system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImportError: dynamic module does not define module export function (PyInit_python_example)

etienne87 opened this issue · comments

I get this error when running pip install . on python_example.
[Config]

  • Linux WSL
  • Ubuntu 20.04
  • python3.8

Try python3 -m pip install .. I think you are using pip from Python 2 and Python 3. I'd recommend always using virtual environments or some other similar mechanism.

Thanks, it works this way!

if i use anaconda i get the following: ImportError: function cffi_pypyinit

That's something for PyPy, cffi is the c foreign function interface, and pypy uses it. Did you expect PyPy instead of Python?

Ah you are right! this was because of pypy installed in my conda env.

I am trying to slightly change the project. Just changing the name from "python_example" to "python_example_v2" give me back this weird error, do you perhaps know why?

PYBIND11_MODULE(python_example, m) {

This must match. CPython (and PyPy) look for a symbol inside the shared library that has the shared library name in it along with a python specific part (PyInit_ prefix on either py2 or py3, I forget which, it changed between 2 and 3). Symbols in multiple shared libraries must be uniquely named so you can load different libraries in a single process.

ahh, got it thank you!

In case this helps anyone. I'm trying to run Kalliope on Ubuntu22 with Python3.10. I was having this error:
File "/usr/local/lib/python3.10/dist-packages/kalliope/trigger/snowboy/snowboydetect.py", line 32, in swig_import_helper _mod = imp.load_module('_snowboydetect', fp, pathname, description) ImportError: dynamic module does not define module export function (PyInit__snowboydetect)

I solved it downloading snowboy from git and compiling swig python3:
git clone https://github.com/Kitt-AI/snowboy.git
cd snowboy/swig/Python3
make

Finally I copied the new snowboydetect.py and _snowboydetect to /usr/local/lib/python3.10/dist-packages/kalliope/trigger/snowboy/, overwriting the old files.