By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

Embedded python: "import" problem

P: n/a
Vio
Hi,
I've been trying to embed (statically) wxPy alongside an embedded py
interpreter on a linux/gtk box.

At one point, for some reason misc.o linking reported "multiple
definitions of wxGetFreeMemory()". Since wxGetFreeMemory() seemed
effectively unused in gtk, I just commented it out in misc_wrap.cpp
(didn't want to patch SWIG to regenerate the wrapper code, so hacked the
generated cpp source), and replaced "result=(long)wxGetFreeMemory();"
with "result=0;". Crossed some fingers...

All compiled and links without errors. (but don't try this at home
folks: an almost 20MB executable)
Anyhow, executing from the embedded interpreter the following:
--------------------

import _core
import _misc
import _windows
import _controls
import _calendar
import _gdi
import _grid
import _html
import _wizard
print dir()
--------------

outputs:
['__builtins__', '__doc__', '__file__', '__name__', '_calendar',
'_controls', '_core', '_gdi', '_grid', '_html', '_misc', '_windows',
'_wizard']
but then continuing with:

--------------

import core
import misc
import windows
import controls
import calendar
import gdi
import grid
import html
import wizard

--------------

Modules - misc, calendar, grid, html, wizard - they all report
ImportError: No module named ...

Related:
--------------

import core

--------------

import core
File "somepath/core.py", line 9444, in ?
from misc import *
ImportError: No module named misc
Which is rather odd. Some unsuccessful hacks:
'core.py': around line 9444 replaced "from misc import *" to "from _misc
import *". Only to get stopped by the next line (and last line) in
"cope.py" with:

../src/helpers.cpp(680): assert "wxAssertFailure" failed: Unable to find
stock object [in child thread]

Commenting out last line of core.py and running:

--------------
print "core.Frame>", core.Frame
print "core.App>", core.App
a = core.App()
--------------

outputs:
core.Frame> <class 'windows.Frame'>
core.App> <class 'core.App'>
Segmentation fault

but if I do:
--------------
a = _core.new_PyApp()
print a
--------------
<core.PyApp; proxy of C++ wxPyApp instance at _e8c2e408_p_wxPyApp>

So I don't quite see the big picture here. The good news is that
embedded py has access to wx classes, albeit in this not very pythonish
raw form, bad news is that I don't quite understand why embedded py
interpreter can import some embedded modules (like core and gdi), but
fails to import some others (like misc or html). I'm not too sure what
causes the segfault, but I suspect some dependencies on the failed
imports perhaps? I included my little hack in misc_wrap.cpp, just in
case it plays a role here which I missed.

Any suggestions welcome, but basically I would appreciate if someone can
point me what possibly could make some of these wx modules to get
imported, and some to give me an Import Error.

Cheers,
Vio
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.