I have defined the name of my wrapper object in my c file blargUtils.c like this (I have defined methods and the lot for it in Blargmethods)…
void initBlarg(){
Py_InitModule("Blarg", Blargmethods);
}
I compiled it like so…
blarglib: blargUtils.c
gcc -I/usr/include/python2.6 -fPIC -c blargUtils.c -Wall
gcc -shared blargUtils.o -o blargUtils.so
clean:
rm *.so
However, when I try to import the wrapper in my python script…
import Blarg
Its says it says: “ImportError: No module named Blarg”. I’m a little lost here and I don’t understand why it cannot find the class when they are the exact same spelling. Maybe its a logic error?
If more code is needed let me know.
First of all, from looking at the comments, I see that renaming it didn’t work. This means (1) python can’t find the .so file, (2) the .so file isn’t usable (i.e. not compiled correctly or not all required symbols are found), or (3) there is a .py/.pyc/.pyo file in the same directory which already has that name. If you have Blarg.py already defined, python will look at this file first. The same goes if you have a directory named Blarg in your search path. So instead of bashing your head against the wall, try this:
1) Rename your .so library to something guaranteed not to collide (i.e. _Blarg)
2) Compile it with the SAME NAME
3) Create a python wrapper (i.e. Blarg.py)
4) Now just use it as normal
Obviously this is a bit of overkill, but it should help you determine where the problem is. Hope this helps.