Module name does not match file name

Steven D'Aprano steve at
Mon Jul 7 09:57:21 CEST 2014

Cut a long story short... 

I'm trying to debug a Tkinter app written in Python. The author of this 
app designed it as a maze of twisty dependencies, all alike, and his idea 
of source control was to make multiple copies of every file and drop them 
in random places on the hard drive. He also has a whole lot of non-
standard, semi-standard, and just plain weird locations added to the 
PYTHONPATH, some of which are added at run time for extra enjoyment, so 
I'm having lots of fun trying to work out which files are being imported 
and where they are being imported from.

I ran the modulefinder tool to get a list of imported modules:

$ python2.6 -m modulefinder /long/path/

but to my surprise, it claims that "import pg" is *not* reading the 
file I located, but instead loading a module with a completely different 

$ python2.6 -m modulefinder /long/path/

  Name                  File
  ----                  ----
m pg                    /usr/local/lib/python2.6/dist-packages/

Can anyone explain how "import pg" can end up coming from

Sure enough:

>>> import pg
>>> pg.__file__

What sorcery is this???


More information about the Python-list mailing list