0

I have made a python wrapping of a c++ class similar to here and here. but the generated python wrapper is only usable in python2 while giving the following error in python3:

dynamic module does not define module export function (PyInit_...)

my setup.py looks like the following:

## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

setup_args = generate_distutils_setup(
    packages=['hw_interface_pkg'],
    package_dir={'': 'src'},
    requires=['std_msgs', 'rospy'],
    language_level="3",
    compiler_directives={'language_level' : "3"}
)

setup(**setup_args)

following this thread I tried adding language_level = "3" or compiler_directives={'language_level' : "3"} to the above setup_args but none solved the problem.

my pyx file also looks like:

cdef extern from "remote_hw.h":
    cdef cppclass ROBOTHardwareInterface:
        ROBOTHardwareInterface() except +
        double c_fibonacci(double n);

cdef class PyHWInterface:
    cdef ROBOTHardwareInterface c_obj
    def __cinit__(self):
        pass
    def fibonnaci_func(self,n):
        return self.c_obj.c_fibonacci(n)

-------------edit

I made sure setup.py is called by python3. but still the same issue.....

9
  • 1
    That's correct. An extension module built with Python 2 will not be usable on Python 3. You need to rebuild it with Python 3 (i.e. invoke setup.py with Python 3). language_level is to do with how Cython interprets the pyx file so is not related to your problem. Commented Jun 17, 2020 at 7:33
  • @DavidW I see, the thing is setup.py is invoked automatically during a so called "catkin build" command where it is likely the "catkin_python_setup()" in the CMakeLists.txt that does it. but it's not clear to me how I can make it invoke setup.py with python3. or any other solution/hack... Commented Jun 17, 2020 at 7:52
  • @DavidW I made sure setup.py is called by python3.6 but still the same issue presists..... Commented Jun 17, 2020 at 10:34
  • What is the output file called? It should be something like filename.cpython-36.so (or .pyx). If it doesn't have an extension with the version in it then it probably isn't being called by Python 3.6. I've never heard of catkin before so have no useful advice on that. Commented Jun 17, 2020 at 11:26
  • @DavidW inside setup.py I had prtint(sys.version), which printed "3.6.9 (default, Apr 18 2020, 01:56:04)". there is a similar issue here: stackoverflow.com/questions/8024805/… although non of the ideas in it has worked for me so far Commented Jun 17, 2020 at 12:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.