This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2015-08-05 08:51 by Amund Hov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22204 merged iritkatriel, 2020-09-11 16:00
Messages (2)
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.
msg383334 - (view) Author: miss-islington (miss-islington) Date: 2020-12-19 00:10
New changeset fb34096140bbb74c81500dd8bbc3c69c1d24d9ab by Irit Katriel in branch 'master':
bpo-24792: Fix zipimporter masking the cause of import errors (GH-22204)
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68980
2020-12-20 17:06:37iritkatrielsetstatus: open -> closed
stage: patch review -> resolved
2020-12-20 17:06:13iritkatrielsetresolution: fixed
versions: - Python 3.8, Python 3.9
2020-12-19 00:10:03miss-islingtonsetnosy: + miss-islington
messages: + msg383334
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