Module name does not match file name
Steven D'Aprano
steve at pearwood.info
Mon Jul 7 03:57:21 EDT 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/script.py
but to my surprise, it claims that "import pg" is *not* reading the pg.py
file I located, but instead loading a module with a completely different
name:
$ python2.6 -m modulefinder /long/path/script.py
Name File
---- ----
[...]
m pg /usr/local/lib/python2.6/dist-packages/pgmodule.so
Can anyone explain how "import pg" can end up coming from pgmodule.so?
Sure enough:
>>> import pg
>>> pg.__file__
'/usr/local/lib/python2.6/dist-packages/pgmodule.so'
What sorcery is this???
--
Steven
More information about the Python-list
mailing list