I am trying out Visual Studio Code, to learn Python.
I am writing a starter piece of code to just take an input from the user, say:
S = input("What's your name? ")
When I try to run this (Mac: Cmd + Shift + B) I see the task is running with no output. I have already configured the tasks.json file for output and arguments.
print("Hello, World!")
S = input("What's your name? ")
Do I need to configure some environment variables in Visual Studio Code?
From the Command Palette (Ctrl+Shift+P), select the Python: Start REPL command to open a REPL terminal for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.
Tasks are intended for building your application. Since Python is interpreted, you don't need to use tasks.json at all to run/debug your Python code. Use the launch.json instead. I am using Don Jayamanne's Python extension for debugging and have configured the launch.json as follows:
Open the Command Palette (Ctrl + Shift + P) and write the command:
start without debugging
Then select your Environment -> Click Python. This should create a launch.json file within a .vscode directory in the current directory.
Paste the following configuration json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"program": "${file}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"console": "integratedTerminal"
}
]}
Save the file, open your python script in the editor and 'start without debugging' again. This should launch an integrated terminal where you can give input as well as see the output.
Ctrl+Shift+d, then choose integrated terminal/console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With