Title: zipimporter masks import errors
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Amund Hov, eric.snow, gregory.p.smith, iritkatriel, ncoghlan, superluser, twouters
Priority: normal Keywords: patch

Created on 2015-08-05 08:51 by Amund Hov, last changed 2020-09-11 16:04 by iritkatriel.

Pull Requests
URL Status Linked Edit
PR 22204 open iritkatriel, 2020-09-11 16:00
Messages (1)
msg248022 - (view) Author: Amund Hov (Amund Hov) Date: 2015-08-05 08:51
Due to mixed version .pyc files in my zipped python application I was getting inconsistent loading of certain packages.


n [4]: zf.find_module('kitconsole')
Out[4]: <zipimporter object "">

In [5]: zf.load_module('kitconsole')
ZipImportError                            Traceback (most recent call last)
<ipython-input-5-8e75885cc952> in <module>()
----> 1 zf.load_module('kitconsole')

ZipImportError: can't find module 'kitconsole'

Unpacking the archive and doing the import from the file system revealed the  real issue, ImportError: Bad Magic Number.

As an end user it was confusing that zipimporter reported being able to find the module in find_module(), but not in load_module(). Is it possible to have load_module provide a better error message when import fails? The wording now does not give any hints when searching the bug-tracker / Google.
Date User Action Args
2020-09-11 16:04:43iritkatrielsettype: enhancement -> behavior
components: + Library (Lib)
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.4, Python 3.5, Python 3.6
2020-09-11 16:00:10iritkatrielsetkeywords: + patch
nosy: + iritkatriel

pull_requests: + pull_request21259
stage: patch review
2020-06-05 19:26:30brett.cannonsetnosy: - brett.cannon
2015-08-05 15:52:21eric.snowsetversions: + Python 3.5, Python 3.6
2015-08-05 15:50:55eric.snowsetnosy: + twouters, brett.cannon, gregory.p.smith, ncoghlan, eric.snow, superluser
2015-08-05 08:53:58Amund Hovsettype: behavior -> enhancement
2015-08-05 08:51:02Amund Hovcreate