Numpy package missing

I have used Binder for my Jupyter Lite code in the Github repository. It is working fine. But when I tried to connect to another repository in the same account, I got the ‘no module’ error for common packages like numpy, matplotlib.

“No module named ‘matplotlib’”

Is the binder connection limited to 1 per GitHub account?

https://mybinder.org/ and JupyterLite are different services.

If you can provide us with detailed information on what you’re doing e.g. links to repositories, step-by-step instructions to reproduce the exact error you’re seeing from scratch, we might be able to provide more help.

  1. I go to URL: https://mybinder.org/
  2. I fill out the details, refer image below

As I am allowed only 1 image embed per post. I will break my reply to 3 posts

  1. I press the ‘launch’ button
  2. I get the jupyter lite interface as shown in the image below

  1. I run the notepad and get the error as shown in the image below:

That is not JupyterLite. In your two screenshots, you can clearly see mention of ipykernel. In the last one it is in the upper right corner in what it is called the kernel status indicator.

The ipykernel is the traditional typical Python kernel

Those screenshots are typical JupyterLab running on a remote machine with a typical, full Python kernel (ipykernel-based).
Please read how to configure a repo with a configuration file (see here to get started & here are the many options) and/or share your actual repo so we can describe accurately what is going on. There’s no public repos at the repositories for that GitHub account you show: xxxx · GitHub . Repos need to be public to work with MyBinder.
If you don’t want to add a configuration file and are fine doing the installs with each new session, you can add the following to a cell near the top of your notebook and run it:

%pip install numpy matplotlib

Then patiently let it run to completion and restart the kernel. Then you should be able to import those packages. And the associated code should work for that session. When you start again, you’ll need to repeat unless you set up a configuration file or use a repo that has a configuration file that has what you need; you could use here if you’d like (you can scroll down to choose JupyterLab or Jupyter Notebook 7+ as the interface you get when the session starts up).

If you point an arbitrary repository at MyBinder that isn’t set up with a configuration file to specify what packages, Python versions, or other software to install there, then you get whatever the current default the MyBinder folks have decided on at the time, which may or may not match well with your needs.

JupyterLite runs with pyodide kernel

JupyterLite uses the Pyodide kernel. (Click here to start it in your browser and you’ll note that it says ‘Python (Pyodide)’ in the upper right corner. Contrast that with what you see at the indicator in your last screenshot.) The code runs deep in your own browser after getting the HTML and associated files to make the site from a remote server. If you use JupyterLite deployed by others you get what they set to install upon initiating and it may not be what you want. If you deploy a JupyterLite yourself, you can configure that to have packages already installed that you want. You can also use the install command I put above to bring things into the current namespace.

You may want to read my post here for a better overview of the two and how they work. One thing different from what I write there is that I would suggest using the Try Jupyter page to launch JupyterLite for now (first few tiles if you scroll down on that page) . The JupyterLite sessions launched from links on the main documentation page don’t allow making notebooks for now.

1 Like

My bad!

I thought it was jupyter lite running. Ok, so this is JupyterLab running on a remote machine with a typical, full Python kernel (ipykernel-based).

Well, the full name of the repository (rambail/Microgrid) and is in this link: Binder. And it is public.

The problem I am facing is that the notebook Microgrid_Nu.ipynb in this repository gives ‘no module’ error for common packages like matplotlib and numpy.

But if I transfer the same file to another repository (rambail/Metro): Binder, it runs without error.

Thanks!

requirements.txt solved it

Yes, the older version of github.com/rambail/Microgrid lacked a configuration file to specify any packages.
Whereas github.com/rambail/Metro has had a requirements.txt for the last two months, and that file listed matplotlib numpy, and ipywidgets and so when the image for that is built the Binder infrastructure recognizes that and builds the image with those packages installed and later you got a session with those already installed.

I will mention that each of those packages can be installed in a fresh session ‘on-the-fly’ from within a running .ipynb file with that magic install command I mentioned in my last post, without needing to have a configuration file. ipywidgets though changes a lot of things and so you need to refresh the browser page for Jupyter to propagate the changes at many levels, in addition to restarting the kernel. It is just easier to have it installed during the build and saves you running the installs in each new session. However, the ability to use the magic command inside the running Jupyter .ipynb file is good to keep in mind when you find yourself in a session you didn’t set up.