pythonvisual-studio-codevscode-code-runner

Visual Studio Code - Code Runner : 'python' is not recognized as an internal or external command, operable program or batch file


I have installed Visual Studio Code (VSC) and Code Runner. When I use the terminal to execute my code it works fine and I get the results in the terminal window:

enter image description here

However, when I try to use Code Runner's keyboard shortcut Ctrl+Alt+NI keep getting this error message: enter image description here

Which baffles me because VSC shows this: enter image description here

I've tried rebooting (solution on another related SO question), creating a new conda environment inside VSC along with what seemed to be relevant from the VSC documentation here and here.

If anyone can help me understand what I need to be doing differently I would appreciate it.


Solution

  • You need to set a symbolic link between calling Python3 and Python since they're effectively the same thing. If you go into a normal command prompt / terminal and type Python3, you may get the same error. Whereas, if you type Python, it will launch the Python interpreter.

    Close VSCode

    If you're a Windows user you can use mklink to sort it out — open a Command Prompt as an Administrator, then navigate to your Python installation. e.g.:

    cd C:\Python38
    mklink python3.exe python.exe
    

    In Linux, you can set a Symbolic link:

    cd /usr/bin/python3
    ln -s python.exe python3.exe
    

    Startup VSCode again and it should work.