You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fullname parameter to zipimporter find_module is documented to be a "fully qualified (dotted) module name". (From http://docs.python.org/library/zipimport.html#zipimport.zipimporter.find_module.) However, passing a fully-qualified dotted module appears to never work. Rather it appears that you must use the file system path separator instead of dots. For example on Windows:
C:\>echo %pythonpath%
\tmp\blah-1.0-py2.6.egg
C:\>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from blah.models import speak
>>> speak.__file__
'C:\\tmp\\blah-1.0-py2.6.egg\\blah\\models\\speak.pyc'
>>> speak.sayhi()
Hi from blah.models.speak sayhi function.
The egg has top-level blah package and under it models, it appears to work fine for normal use. But zipimport zipimporter find_module won't find the models sub-module using dotted path notation:
Was also just bitten by this, trying to muck with PEP-302-style import hooks. Note that the documented behaviour of zipimporter is also the behaviour required by PEP-302, i.e. full dotted module name.
cool-RR commented on Apr 27, 2011
cool-RRmannequin
Mannequin
More actions
I was bitten now as well...
tjdrodgers commented on Nov 13, 2012
tjdrodgersmannequin
Mannequin
More actions
I have also just been bitten by this. Is there anyway that this can be updated to support the dotted notation?
tjdrodgers commented on Nov 14, 2012
tjdrodgersmannequin
Mannequin
More actions
It gets worse. Even though find_module works with the path separator, load_module fails.
>>> zi.find_module("lib\\ui")
<zipimporter object "dist/Test_Editor-1.0-py3.2.zip">
>>> zi.load_module("lib\\ui")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dist/Test_Editor-1.0-py3.2.zip\lib\ui\__init__.py", line 9, in <module>
File "dist\Test_Editor-1.0-py3.2.zip\lib\ui\texteditorwindow.py", line 5, in <module>
File "dist\Test_Editor-1.0-py3.2.zip\lib\ui\designer\__init__.py", line 5, in <module>
ValueError: Attempted relative import beyond toplevel package
tjdrodgers commented on Nov 14, 2012
tjdrodgersmannequin
Mannequin
More actions
Disregard the last...error on my part (so embarrassing!)
Actually find_module() should be deprecated and find_spec() should be defined instead (and the same goes for load_module(); see bpo-9699). So I'm personally fine w/ making this a doc problem w/ the plan to eventually deprecate the method.
Activity
kmtracey commentedon Apr 14, 2010
The fullname parameter to zipimporter find_module is documented to be a "fully qualified (dotted) module name". (From http://docs.python.org/library/zipimport.html#zipimport.zipimporter.find_module.) However, passing a fully-qualified dotted module appears to never work. Rather it appears that you must use the file system path separator instead of dots. For example on Windows:
C:\>echo %pythonpath%
\tmp\blah-1.0-py2.6.egg
The egg has top-level blah package and under it models, it appears to work fine for normal use. But zipimport zipimporter find_module won't find the models sub-module using dotted path notation:
On Linux, the 'blah/models' version is the one that works.
Tested as far back as Python2.3 and as far forward as 2.7a3.
rfk commentedon Jul 7, 2010
Was also just bitten by this, trying to muck with PEP-302-style import hooks. Note that the documented behaviour of zipimporter is also the behaviour required by PEP-302, i.e. full dotted module name.
cool-RR commentedon Apr 27, 2011
I was bitten now as well...
tjdrodgers commentedon Nov 13, 2012
I have also just been bitten by this. Is there anyway that this can be updated to support the dotted notation?
tjdrodgers commentedon Nov 14, 2012
It gets worse. Even though find_module works with the path separator, load_module fails.
tjdrodgers commentedon Nov 14, 2012
Disregard the last...error on my part (so embarrassing!)
tirkarthi commentedon May 15, 2019
This still exists after zipimport rewrite in Python with 3.8 . Is this a documentation issue or an enhancement to be made as noted in msg109467 ?
brettcannon commentedon May 16, 2019
Actually find_module() should be deprecated and find_spec() should be defined instead (and the same goes for load_module(); see bpo-9699). So I'm personally fine w/ making this a doc problem w/ the plan to eventually deprecate the method.
hugovk commentedon Aug 16, 2022
Closing this as
find_moduleis deprecated since 3.10 and slated for 3.12 removal: