How to setup Code Runner in Visual Studio Code for Python

300 picture 300 · Jun 4, 2018 · Viewed 40.5k times · Source

I have installed Visual Studio Code 1.23.1 and added extensions - Python, Code Runner.

With Code Runner, now I can see the Run Code symbol (triangle) and on highlighting it, I see the shortcut Ctrl + Alt + N. But when I try to use it to run the code that asks for user input, I can't find a way to provide the input. When I try to enter user input, I get error message "Cannot edit in read-only editor". I think this is because I am missing some configuration part for Code Runner like setting up PATH or some other Workspace settings.

Question: Please assist me in identifying what all configuration will I need to do and how?

I did select "Add Python 3.6 to PATH" while installing Python. I have attached screenshots for reference:

ExecutionError ExecutionError

Note: Even now when I right click and select "Run Python File in Terminal" for the same program, I can enter user input fine and get the expected output. ExecutionWorking

Answer

Lukewcn picture Lukewcn · Nov 21, 2018

Here's another alternative answer, I think more accurate.
Add following settings to your vscode user settings file:

"code-runner.executorMap": {
    "python": "$pythonPath -u $fullFileName",
},

Check out this reference for some useful variables: Variables Reference