0

My script begins with the following:

# %%
%matplotlib qt
import importlib
import sys
import matplotlib.pyplot as plt

I am using visual studio code. The script is not a .ipynb file, but a simple .py script. When I use the utility to run the block as a cell, everything works fine, but when I try to run the whole, I get an the following error:

"resource": "/c:/Users/Ariel/Documents/Courses/Tesi/Code/002-test_preprocessing.py",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "Expected expression",
"source": "Pylance",
"startLineNumber": 2,
"startColumn": 1,
"endLineNumber": 2,
"endColumn": 2

My VSCode version is

Version: 1.78.2 (user setup)
Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
Date: 2023-05-10T14:39:26.248Z
Electron: 22.5.2
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: No

I tried to substitute the line with

import matplotlib
matplotlib.use('Qt5Agg')

but this time I have the problem that if I run this ac cell. The plots open in new windows, but I have no way to stop the execution of the cells.

I also tried to run again

pip install pyqt5 --upgrade
pip install matplotlib --upgrade
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • That % prefix is a Jupyter/IPython command, you cannot use it in scripts. Explain what do you mean by "stop the execution of the cells"; if you want to use a script as a program, you cannot "interrupt" it as you'd do with an interactive shell (or a debugging function), you have to provide that functionality in the program logic. – musicamante May 16 '23 at 14:24
  • thanks for your reply! i mean that when i generate a plot, the figure appear in a window (using jupyter) and the cell appears to run continuously (i suppose because i'm interacting with the window). But even when i close the window the cell is still executing something, and the only way i found to proceed is to manually send an interrupt – arielpriarone May 16 '23 at 15:53
  • I've never actively used matplotlib, so I really don't know what you mean by "the cell appears to run continuously". Maybe you're using a translator and you actually mean something else? – musicamante May 16 '23 at 18:31
  • By that i mean that while the popup is open, the cell appears "running" (VScode show that my the rotating arrows and the fact that a stop button appears). There is no way to run the next cell directly, because even closing the plot, the cell will be executing something forever. The only way to run another cell is to manually restart the kernel and then run a different cell – arielpriarone May 17 '23 at 11:07

0 Answers0