Oct-19-2021, 07:24 PM
(This post was last modified: Oct-19-2021, 07:24 PM by deanhystad.)
There are lots of ways to run code in VSCode.
Are you using "Run Selection/Line in Python Terminal" from the context menu that pops up when you right click in the text editor view? I get this error of I run your program that way without making a selection.
"Run Python File in Terminal" from the context menu works for me.
"Run XXX in Interactive Window" requires I install ipykernal to use. When I select this option it creates a jupyter like interface where I enter python code in cells.
I usually use the run arrow near the upper right corner ("Run Python File in Terminal") or the "Start Debugging" or "Run Without Debugging" options under the "Run" menu. All of these run your program without problems.
What extensions do you have installed in VSCode? I have Python and PyLance. I also installed Jupyter because I wanted to get a feel for how that works. I think installing the Jupyter extension is why I get the "Run XXX in Interactive Window" choices in the code context menu.
So how are you running your program when you have this problem?
Are you using "Run Selection/Line in Python Terminal" from the context menu that pops up when you right click in the text editor view? I get this error of I run your program that way without making a selection.
x = 5 print(x)
Error: File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
Notice the error says the problem is in line 1, but obviously the error is in line 2. If you don't make a selection, this command uses the line containing the cursor. So it ran this programprint(x)And this program has an error in line 1.
"Run Python File in Terminal" from the context menu works for me.
"Run XXX in Interactive Window" requires I install ipykernal to use. When I select this option it creates a jupyter like interface where I enter python code in cells.
I usually use the run arrow near the upper right corner ("Run Python File in Terminal") or the "Start Debugging" or "Run Without Debugging" options under the "Run" menu. All of these run your program without problems.
What extensions do you have installed in VSCode? I have Python and PyLance. I also installed Jupyter because I wanted to get a feel for how that works. I think installing the Jupyter extension is why I get the "Run XXX in Interactive Window" choices in the code context menu.
So how are you running your program when you have this problem?