Reputation: 19
When I try to run Python code in the terminal with a print command, nothing happens. When I try the test.py
command in the terminal itself, the text copied below is what gets output.
Please assist in how to get the terminal to print my code.
cd E:\Kath\Documents\blockchain
test.py
Output:
test.py : The term 'test.py' 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:1
+ test.py
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound:
(test.py:String) [], CommandNotFoundExce
ption
+ FullyQualifiedErrorId : CommandNotFound
Exception
Upvotes: 1
Views: 5443
Reputation: 11
Once you open the VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available. Now, create a new file, and save it with the extension .py. Once done this, write the required code in the workspace. And then Right Click on the workspace -->Run Python file in the terminal. This runs the selected file. Hope this solution helps.
Upvotes: 1
Reputation: 2018
In "Terminal" you get what is essentially a regular Command prompt, and command interpreter in your case is PowerShell.
So, to execute the python script you should run it as:
python test.py
or
python3 test.py
or similar, depending of your python executable.
As Powershell is your default command shell in Visual Studio Code, if the ".py" extension is registered with Python, you can try:
.\test.py
If you use virtual environments, make sure you select the correct Python interpreter.
Upvotes: 0