'Import sys' succeeds in C++ embedded code, but module is not fully visible

Ben Sizer kylotan at gmail.com
Thu Jan 15 19:47:39 EST 2009


On Jan 14, 4:37 pm, Ivan Illarionov <ivan.illario... at gmail.com> wrote:
> On Jan 14, 1:49 pm, Ben Sizer <kylo... at gmail.com> wrote:
>
> > No, I don't want to do anything with sys.path apart from see it. I
> > just wanted my original question answered, not a guess at my intent
> > and a solution for something I'm not doing. ;)  Thanks though!
>
> > Again - why can I not reference sys from within the function?
>
> Ah, sorry for wrong guess.
>
> I would try to use ourNamespace_ dict for
> both globals and locals in PyRun_String call.

Yes, this seems to fix it, thanks. But why? Can some Python guru
explain why these two dictionaries must be the same? (Or what steps we
must take if we want them to be separate?) The documentation is not
very clear. I had hoped to be able to clear out the locals dictionary
while leaving useful functions intact in the globals dictionary, but
it would appear that is not practical.

(On a separate note, while trying to debug this it seemed that Python
will look for debug versions of a library when you embed it in debug
mode, and will fail to find a module if you only have the release
versions there. The error message you get isn't too helpful about this
however, and I only worked it out by looking at the very long list of
filesystem calls Python made to try and find it. Anybody wishing to
speed up import times might want to ensure they don't have a long
Python path and as few eggs in site-packages as possible.)

--
Ben Sizer



More information about the Python-list mailing list