Python Embedding / Import Woes

Corey Donicz cdonicz at cri-inc.com
Mon Mar 18 12:11:27 EST 2002


I'm trying to resolve how to properly handle python module imports
from within an embedded python interpretor.

I've been able to reduce the problem to a simple case scenario:
After Py_Initialized() is called, as a test case, I run:
PyRun_SimpleString("from Numeric import *");

What I get is the following traceback:
File "<string>", line 1, in ?
File "C:\Program Files\Python21\Numeric\Numeric.py", line 133, in ?
  import multiarray
ImportError: No module named multiarray

I've checked that the python path points to the proper dirs, and I've
also cross checked the behavior in from a python interactive shell
which does _not_ result in the import error.  I keep getting bizarre
failures to find modules when my embedded code calls upon an external
module which has an "from foo import *" type import.  I feel I should
also mention that the embedded application is not relying on
PyRun_SimpleString at all, that's just in there for testing.

I'm guessing that since my sys.path is correct, that I'm not managing
namespaces correctly.

Any insights into this would be greatly appreciated.
Thanks in advance.

-Corey



More information about the Python-list mailing list