Running a script in JupyterLab

Elisa Tau
  • 1
  • 18 Jan

Hi!
I'm trying to run a script in a JupyterLab terminal but I keep getting some errors that I don't understand and that prevent the code from running correctly. Firstly, I tried doing it using the "python + filename.py" command, but it seems that there is a problem importing some libraries. Secondly, I tried running a notebook script by using the "python + notebookname.ipynb" command, but I recieved another error message. Finally, I tried running both scripts using ipython, but I had the same problem with the importation of libraries (specifically with matplotlib.pyplot, which is odd) because it also said it "failed to import any qt binding".
I'm attaching the screenshots in which you can see these errors. What should I do?
Many thanks in advance!
Elisa.

Captura de pantalla_2022-01-18_18-15-43.png

Captura de pantalla_2022-01-18_14-42-44.png

Captura de pantalla_2022-01-18_18-17-12.png

Dylan Nelson
  • 19 Jan

For plotting there are two options:

(1) Make plots in a Jupyter notebook.
(2) Make plots and save them to a file, e.g a PNG or PDF.

You cannot interactively see plots on the screen from the console.

The error you are seeing is due to the choice of matplotlib backend, i.e. by default it is trying to open a window on the screen.

You can try running export MPLBACKEND=Agg in the console to switch to the file based backend. (You can add this line to your .bashrc file to make it permanent).

Elisa Tau
  • 1
  • 27 Jan

Hello, Dylan!

Thank you for your response. Actually, my problem arises when I try to "import matplotlib.pyplot". However, in the past, I have run notebooks that have that import sentence (either interactively, or by submitting the job ("run script.py")) and I haven't had any problem in the past.

Now, inside the ipython console, if I put "import matplotlib.pyplot", an error is raised. This also happens when I run a notebook that contains that import sentence, even if I don't do any plot.

This has not happened before, so I was wondering if something has changed in the platform.

Best wishes,
Elisa

Dylan Nelson
  • 27 Jan

Hi Elisa,

What i mean is this (in a console in the Lab):

$ echo $MPLBACKEND

$ ipython
>>> import matplotlib.pyplot
[many errors as your screenshot shows]

$ export MPLBACKEND=Agg
$ ipython
>>> import matplotlib.pyplot
[works successfully]
  • Page 1 of 1