Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to solve "ImportError: dynamic module does not define module export function"

The is the link to the python package I am trying to compile and install. I have tried what I can find online for hours but cannot get over the ImportError.

The package has the following contents.

enter image description here

Its setup.py has the following content. There are two modules here. One is the python wrapper package with sparse_learning, the other is a c extension module named proj_module.

enter image description here

I followed the procedure described here https://docs.python.org/3.6/extending/building.html to compile and install on Ubuntu 18.04. There is no error message.

sudo python3 setup.py build_ext --inplace enter image description here

sudo python3 setup.py install

Then when I try to load the C-extension module proj_module, an error "ImportError: dynamic module does not define module export function" occurs.

python3 -c "import proj_module"

enter image description here

I tried to apply solutions found online, including uninstalling Python2 with sudo apt purge python2.7-minimal, or add python3 site-packages paths to the bashrc. However, none of them worked. enter image description here


I just know it was originally written for Python 2. Then two modifications are made in the main_wrapper.c for it to run for Python 3. They look correct to me...

Added: enter image description here

Changed: enter image description here

like image 936
Tony Avatar asked Mar 21 '19 09:03

Tony


1 Answers

It looks like you've got a little bit of Python 2-style code mixed in with your Python 3 module here. You just need to replace

PyMODINIT_FUNC initproj_module() {

with

PyMODINIT_FUNC PyInit_proj_module() {

in your main_wrapper.c file.

like image 185
Nathan Vērzemnieks Avatar answered Oct 17 '22 20:10

Nathan Vērzemnieks