Intermittent ModuleNotFoundError when upgrading a pure‑Python package via <py-env> in PyScript
0 reputation · 14 Feb 2026, 16:42 UTC
0 reputation · 14 Feb 2026, 16:42 UTC
When the <py-env> tag is updated to request a newer version of a pure‑Python wheel, subsequent <py-script> blocks sometimes fail with ModuleNotFoundError or continue to use the old cached version.
Determine a reliable pattern that lets a small browser‑based application load a new package version without a full page reload while guaranteeing that the code that follows sees the updated module.
<py-env>) runs asynchronously; the wheel extraction may not finish before the next script block executes.These factors make it unclear which approach—awaiting micropip.fetch, using an onload handler, or wrapping imports in a reload function—provides deterministic zero‑downtime migration for a pure‑Python dependency.
What is the recommended way to ensure the new package is fully extracted and available before dependent <py-script> blocks run? Can the onload attribute of <py-env> be relied upon to swap imports safely without a page reload? Is it necessary to re‑import the module via importlib.reload after the load completes, or are there alternative patterns that avoid manual reloading?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.