Open sylee957 opened 1 year ago
Apparently running import matplotlib
installs matplotlib on the fly. But somehow this doesn't happen for the import matplotlib
line that happens internally in the plotting module. Ideally any import that happens internally in SymPy should also install the module if it can, because those imports represent optional dependencies which enhance SymPy's capabilities.
NumPy is the same way. If you call lambdify
, it will create a function that doesn't use the NumPy backend. But if you import numpy first it uses numpy:
Another thought: basically all external imports in SymPy go through this import_module()
function. So we could potentially add some code in there to automatically import things if we detect we are in SymPy Live (this could either be added directly in SymPy or monkeypatched in SymPy Live).
Although I would like to understand why this is happening first. Maybe the problem is that pyodide intercepts import
statements syntatically but import_module
is using __import__
. If that's the case, it would be better for pyodide to hook into Python's import mechanisms directly.
I see that the matplotlib is not recognized by the default backend in plots.
However, pyodide has matplotlib installed, so
import matplotlib
prepending just worksI wonder if this can be appended to the templates, or sympy plot should recognize this to load matplotlib on demand. (if loading matplotlib is heavy)