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.
Dylan Nelson
19 Jan '22
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).
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.
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.
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).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
Hi Elisa,
What i mean is this (in a console in the Lab):