-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import numpy fails from script run with IPython %run magic #65
Comments
Yes: the loadPackagesFromImports of pyodide standard distribution packages only works at the plain python AST level. This mechanism doesn't work with nested imports (e.g. This kernel exerts a bit more control over if sys.modules.get("pyodide"):
%pip install -r requirements-numpy.txt Where the new requirements file was like: numpy
-r requirements.txt Which would load: ipywidgets
# whatever else... Another path is to build a wheel that encapsulates the needed dependencies, and ship that in |
OK. Thanks for the feedback, although to be honest, I got lost towards the middle! Anyway, in the meantime, I've inserted a "collective" I agree that at some point it would be nicer to prepackage all dependencies, to avoid my demo from breaking repeatedly! However, for the moment, I enjoy the "opaque simplicity" of the deployment based on Github actions (thanks to the demo template repo). I don't fully understand how it works, but it mostly works! |
Another approach would be to use jupyterlite-xeus-python which allows you to pre-package any dependency that you need. You just need an |
Yes, I saw this mentioned in other threads. However, one of the demo uses a pure Python package of mine which I only published on PyPI (while jupyterlite/xeus-python-kernel needs conda-forge). But in one of these threads I saw this limitation was to be overcome, so that would become very useful indeed! |
Pip packages is now supported since recently (see this section of the docs) though it installs them with the |
Hello,
I have a strange (i.e. only half reproducible) failure of
import numpy
in script run from a notebook with the%run -i
IPython magic.I have two deployments of jupyterlite/demo, with the same
requirements.txt
(pierre-notebooks/requirements.txt and Microgrids.web/requirements.txt) based on jupyterlite/demo#128 (15 Sept 2023).In both repos, I have "no-code" notebook demos with interactive plots (matplotlib+ipywidgets) where most of the code is hidden in a setup script :
The common structure of these notebooks is:
try: import piplite
block so that the exact same notebook can also be run an classical (non-Lite) Jupyter Lab.%run -i
) a setup Python script which hides from the userimport numpy as np
and many lines of code.Now come the strange behavior:
Now, if I create a new cell with
import numpy
, this import works fine and then I can rerun the cell which runs the script (which then fails on the next imports: scipy and matplotlib...)I understand from the Pyodide doc loading package mentioned in the error message that there is a special import hook in the REPL that automates the
piplite.install
call for pre-packaged packages. Perhaps then it is not recommented to import such packages in a%run -i
run script?The strange thing is that it works in one JupyterLite deployment and not in the other. I could only spot small differences between the two:
ipywidgets
+ another pure Python package from PyPIipywidgets
%run -i
is surrounded by quotes)→ this starts looking like the game https://en.wikipedia.org/wiki/Spot_the_difference... ;-)
Context
Versions:
The text was updated successfully, but these errors were encountered: