I'm trying to write a simple module in C++ and import it into Python. However, when I try to import the module using import greet
, I get a ImportError: dynamic module does not define module export function (PyInit_greet)
error.
After reading another SO question related to this problem (here) I thought that I may be having version problems (since I'm using Python3.5). But then again, every command I'm using to build and install, I'm using with Python3.5, so how could I be having version problems? (python3.5 build setup.py
and python3.5 setup.py install
).
I'm trying to create a modified version of the simple project described in the Python Docs (here), and everything works fine until I try to import the module.
Here is my setup.py
file:
from distutils.core import setup, Extension
greet_module = Extension('greet',
define_macros=[('MAJOR_VERSION','1'),
('MINOR_VERSION','0')],
include_dirs=['/usr/local/include'],
# clang: warning: libstdc++ is deprecated; move to
# libc++ with a minimum deployment target of OS X 10.9
sources=['greet.cpp'])
setup (name='Greet_Package',
version='1.0',
description='This is a demo package',
author='ralston',
author_email='null',
url='https://google.com',
long_description='''This is really just a demo package''',
ext_modules=[greet_module])
Could it be related to my include_dirs
parameter? My Python3.5 isn't actually installed there, but I tried putting my Python3.5 path in include_dirs
but I got the same error. When I build setup.py
here's my output:
running build
running build_ext
building 'greet' extension
creating build
creating build/temp.macosx-10.6-intel-3.5
/usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -DMAJOR_VERSION=1 -DMINOR_VERSION=0 -I/usr/local/include -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c greet.cpp -o build/temp.macosx-10.6-intel-3.5/greet.o
creating build/lib.macosx-10.6-intel-3.5
/usr/bin/clang++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-3.5/greet.o -L/usr/lib -o build/lib.macosx-10.6-intel-3.5/greet.cpython-35m-darwin.so
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
Any help would be greatly appreciated.