#78 Importing submodule from c-extension fails

open
nobody
None
5
2005-09-20
2005-09-20
Mark E
No

This is a simplification of an existing application which
hopefully describes the essence of the problem.

I'm writing a package consisting of C-Extensions and
regular python modules. The package root
is "pyconnect", and the c-extensions live
in "pyconnect.cextras".

There is a module of some basic code
in "pyconnect\cextras\_pyshared.pyd" and a module of
slightly more high level code
in "pyconnect\cextras\_pyheadertrailer.pyd".

The module "msggui.py"
imports "pyconnect.cextras._pyheadertrailer". The init
function for "pyconnect.cextras._pyheadertrailer.pyd"
attempts to import "pyconnect.cextras._pyshared". If
this fails it exits with a fatal error; otherwise it initialises
its module. The basic code is as follows:
<code>
init_pyheadertrailer(void)
{
PyObject *ppyobjPySharedModule =
PyImport_ImportModule("pyconnect.cextras._pyshared");

if (ppyobjPySharedModule == NULL)
{
Py_FatalError("Failed to import
\"cextras._pyshared\". Check the module exists and is
in the python path");
}
else
{
ppyobjModule = Py_InitModule3
("_pyheadertrailer", g_amethodPyHeaderTrailer, "");
}
}
</code>

The setup script boils down to:
<code>
from distutils.core import setup
import py2exe

setup ( name='msggui',
console= ["msggui.py"]
)
</code>

Using py2exe 0.6.2 with python.org's Python 2.4.1
Windows 2000, and Visual Studio 2003. Installed
py2exe from downloaded install package. Running setup
script seemed to work fine. Running generated
executable produces following output:
<output>
Fatal Python error: Failed to
import "cextras._pyshared". Check the module exists
and is in the python path

This application has requested the Runtime to terminate
it in an unusual way.
Please contact the application's support team for more
information.
</output>

Running in the debugging shows the following:
'msggui.exe':
Loaded 'C:\code\scripts\dist\_pyheadertrailer.pyd',
Symbols loaded.
'msggui.exe':
Loaded 'C:\code\scripts\dist\_pyshared.pyd', Symbols
loaded.
Fatal Python error: Failed to
import "cextras._pyshared". Check the module exists
and is in the python path

Discussion


Log in to post a comment.