Python Embedding Importing relative modules

moerchendiser2k3 googler.1.webmaster at spamgourmet.com
Mon Jul 5 19:49:49 EDT 2010


Hi all,

I have a serious problem I haven't solved yet, hope one of you can
help me. The first thing is, I embedded Python into my app and I
execute several scripts in this environment.

The problem is, the scripts don't import modules from their relative
path. I guess this is related to the sys.path ['',...] and the current
working directory which is set to the directory of my host
application.

I could set that path manually, but all the scripts might be stored in
different locations. So now I try to find a way to handle that. Any
suggestions?

A solution would be, that each script, appends its own directory to
the system path, but this might lead to problems. Imagine all of them
have a module called 'foo.py' and its not the same. This might lead to
name conflicts, wouldnt it?

Btw, I found a source code line in the documentation, where I should
really get rid of the ['', ...] path in the system path due to
security reasons.

import sys; sys.path.pop(0)


Hope one of you can help me out here. Really thanks!!

Bye,

moerchendiser2k3



More information about the Python-list mailing list