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?
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.