Description
When running Python code that includes imports like import matplotlib.pyplot as plt, the sandbox's dependency installer attempts to install matplotlib.pyplot as if it were a standalone package. This results in errors such as:
Failed to install required Python packages: matplotlib.pyplot. This is likely because these packages are not available in the Pyodide environment.
However, matplotlib.pyplot is a submodule of matplotlib, not a top-level package. Only matplotlib should be installed (or checked for availability).
To Reproduce
- Run any Python code in the sandbox environment that includes:
import matplotlib.pyplot as plt
- Observe that the environment attempts to install
matplotlib.pyplot and fails.
Expected behavior
The dependency manager should only attempt to install/check top-level packages (the first part of the import, e.g., matplotlib), not submodules (like matplotlib.pyplot).
If the top-level package is present, all submodules should import without additional installation.
Proposed solution
- When parsing imports and determining which packages to install, extract only the top-level module name (everything before the first
.) for installation checks.
- For example, both
import matplotlib.pyplot and import matplotlib should only trigger an install/check for matplotlib.
Example
This code:
import matplotlib.pyplot as plt
should only cause the dependency resolver to check for or install matplotlib.
Additional context
This behavior breaks standard Python workflows where submodules are routinely imported. It also prevents plotting with matplotlib in environments that otherwise support it.
Description
When running Python code that includes imports like
import matplotlib.pyplot as plt, the sandbox's dependency installer attempts to installmatplotlib.pyplotas if it were a standalone package. This results in errors such as:However,
matplotlib.pyplotis a submodule ofmatplotlib, not a top-level package. Onlymatplotlibshould be installed (or checked for availability).To Reproduce
matplotlib.pyplotand fails.Expected behavior
The dependency manager should only attempt to install/check top-level packages (the first part of the import, e.g.,
matplotlib), not submodules (likematplotlib.pyplot).If the top-level package is present, all submodules should import without additional installation.
Proposed solution
.) for installation checks.import matplotlib.pyplotandimport matplotlibshould only trigger an install/check formatplotlib.Example
This code:
should only cause the dependency resolver to check for or install
matplotlib.Additional context
This behavior breaks standard Python workflows where submodules are routinely imported. It also prevents plotting with
matplotlibin environments that otherwise support it.