[Pyrex] Pyrex importing question.
Blake Winton
bwinton at latte.ca
Fri Nov 12 20:07:26 CET 2004
I seem to be running in to a problem importing a Python module from a
pyrex module.
The first couple of lines of my pyx file are:
x = open( r"c:\hslog.txt", "a" )
x.write( "Initialization!\n" )
x.close()
import conduit.ConduitImpl
x = open( r"c:\hslog.txt", "a" )
x.write( "import conduit.ConduitImpl\n" )
x.close()
The first few lines of the method I'm calling are:
cdef extern long ConfigureConduit( CCSyncPreference* prefs ):
# warm up python
Py_Initialize()
initbtest() # mandatory
# Initialisation done - we can now do Python stuff
x = open( r"c:\hslog.txt", "a" )
x.write( "ConfigureConduit\n" )
x.close()
conduit.ConduitImpl.ConfigureConduit()
x = open( r"c:\hslog.txt", "a" )
x.write( "Done Configuring Conduit.\n" )
x.close()
And the first few lines of ConduitImpl.py are:
x = open( r"c:\hslog.txt", "a" )
x.write( "In import ConduitImpl.\n" )
x.close()
def ConfigureConduit():
x = open( r"c:\hslog.txt", "a" )
x.write( "In ConfigureConduit\n" )
x.close()
As an added twist, I'm using py2exe to bundle up python, and all the
libraries it needs into a few dlls, a zip file, and some pyds.
Now, the problem I'm running into is that when I try to call the
ConfigureConduit method from my C program, I get the following in
c:\hslog.txt:
Initialization!
ConfigureConduit
And that's all. This leads me to believe that the
"import conduit.ConduitImpl" line is failing, but I don't know of any
particularly good way to find out how or why. Looking at the generated
.c file, the line that seems to fail is:
__pyx_3 = __Pyx_Import(__pyx_k4p, 0); if (!__pyx_3) {__pyx_filename =
__pyx_f[0]; __pyx_lineno = 4; goto __pyx_L1;}
and the first line of __Pyx_Import is:
__import__ = PyObject_GetAttrString(__pyx_b, "__import__");
There's a thread at:
http://groups.google.com/groups?hl=en&lr=&threadm=mailman.1028062003.32422.python-list%40python.org&rnum=1&prev=/groups%3Fq%3Dpyrex%2Bpy2exe%2Bimport%26hl%3Den%26btnG%3DGoogle%2BSearch
which looks like it offers a solution to a problem which might be
similar to mine, specifically it suggests that Pyrex should use
PyImport_ImportModuleEx() instead of __import__. But this advice was
offered back in 2002. So, has anyone done anything about it? Was it
decided to be a bad idea for some reason, or did it just slip through
the cracks? Should I try to patch it in to the import_utility_code
variable in ExprNodes.py, and if so, does anyone have any suggestions,
or things I should watch out for?
Thanks,
Blake.
More information about the Pyrex
mailing list