[PyQt] Eric3 issue: importing modules with the same name as an Eric module

Detlev Offenbach detlev at die-offenbachs.de
Wed Sep 26 18:02:54 BST 2007


On Mittwoch, 26. September 2007, Sundance wrote:
> Detlev Offenbach wrote:
> > That is strange. eric puts the path of the executable at sys.path[0]
> > just before it's own path. Can you check sys.path in your main
> > routine or just before the failing import?
>
> Hi Detlev,
>
> Thank you for your reply!
>
> I did check sys.path just before the failing import. This being said, I
> don't think sys.path is used at all here, as you will see below.
>
> Anyway, here's how to reproduce the bug: create these two files:
>
> ---[ test.py ]---------------------------------------------------------
> import sys
> print "Path:"
> print sys.path
>
> import Config
> print "Config file:"
> print Config.__file__
> -----------------------------------------------------------------------
>
> ---[ Config.py ]-------------------------------------------------------
> print "I am the Config.py file!"
> -----------------------------------------------------------------------
>
> ... and run test.py from Eric.
>
> The output will be something like this:
>
> ---[ (output) ]--------------------------------------------------------
> Path:
> ['/home/me', '/usr/share/eric/modules/DebugClients/Python',
> '/usr/share/eric/modules', ...] Config file:
> /usr/share/eric/modules/DebugClients/Python/Config.pyc
> -----------------------------------------------------------------------
>
> As you can see, the sys.path is correct, but the wrong Config module is
> imported.
>
> What is happening here is, I think, that the Python interpreter instance
> which Eric starts in order to run my program, isn't 'clean': it imports
> its own Config module BEFORE even running my code, and thus, when my
> code tries to 'import Config', that Python interpreter goes, "Oh, but I
> already have a Config module loaded, so I'll just return a reference to
> that one".
>
> Am I correct in my assumption that the Python interpreter instance loads
> its own Config module before running my code? Or is it a bug?
>

You are right! And here are instructions for fixing it.

1. Rename DebugClients/Python/Config.py to DebugClients/Python/DebugConfig.py.
2. In DebugClients/Python/DebugClientBase.py change the respective import 
statement (line 27) to read "from DebugConfig import ConfigVarTypeStrings"
3. In Debugger.Config.py change the respective import statement (line 10) to 
read "from DebugClients.Python.DebugConfig import ConfigVarTypeStrings".

-- 
Detlev Offenbach
detlev at die-offenbachs.de


More information about the PyQt mailing list