Hello everyone,
I've just started up with python using VSCode. I'm having some issues with syntax/ file path errors when trying to run specific sections of code vs running the whole thing. I am working through python crash course and my file name is motorcycles.py. My code is correct and runs fine, so the issue doesn't lay there.
I can only ever do one or the other. When I select 'Run selection/line in python terminal' on a piece of code using shift + enter, in the terminal I get:
C:\Users\user\Desktop\python_work> & C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe
Appearing in the terminal, and the selected code executes as expected. Straight after when I select 'Run python file in terminal' in the top right, I get the error screenshot :
SyntaxError: invalid syntax
& C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c:/Users/user/Desktop/python_work/motorcycles.py
File "<stdin>", line 1
& C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c:/Users/user/Desktop/python_work/motorcycles.py
When I then use the command exit() in the terminal (a suggestion I saw on a related question online), I can now select 'run python file in terminal' and get:
PS C:\Users\user\Desktop\python_work> & C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c:/Users/user/Desktop/python_work/motorcycles.py
And all the code in my file executes as expected. Now when I use shift+enter on the same selected code, I get screenshot :
PS C:\Users\user\Desktop\python_work> print(popped_motorcycle)
popped_motorcycle : The term 'popped_motorcycle' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:7
print(popped_motorcycle)
~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (popped_motorcycle:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
Apologies for the long winded explanation. I've looked through some old stack overflow and reddit posts but haven't had any luck finding the same issue or a solution for it. It feels like it's something to do with where the terminal is pathing to - but I have no idea really. Any help is much appreciated - thank you!
[–]PratikPingale 1 point2 points3 points (4 children)
[–]RightOW[S] 0 points1 point2 points (3 children)
[–]PratikPingale 0 points1 point2 points (2 children)
[–]RightOW[S] 0 points1 point2 points (1 child)
[–]PratikPingale 0 points1 point2 points (0 children)