Visual Studio Code error while running Python code by Code Runner on Ubuntu

1.3k views Asked by At

I changed my operating system on Ubuntu 2 weeks ago. I installed Visual Studio Code and an extension Code Runner. When i wanted to run a code i got a following information:

/bin/sh: 1: python: not found

I searched the internet and i found that i have to print at the beginning of my code:

#!/usr/bin/python3

My question is can i change it somewhere in VSCode settings or somewhere else so as not to print this sequence whenever i want to make a new project. Also when I had this extension on Windows i didn't have such a problem. Moreover when i run code in C++ or in other languages i don't have this problem, i have it only in Python. Also i don't have this problem without Code Runner extension. I have it only with Code Runner extension and when i want to run Python code. Picture to visualize a problem.

Code Runner Problem

1

There are 1 answers

0
random_hooman On BEST ANSWER

What the problem here is that, in most of GNU/Linux os, the command for python if you're running python3 is python3 instead of as in windows simply python, the simple python command only works for python2 in linux. So you can do 2 things first, go to ~/.bashrc, open it in any text editor, at the end add this

alias python="python3"

or if you don't want to add an alias, you can make python to python3 in code runner, to do this, do this:

  1. Go to settings
  2. Search for code-runner.executorMap
  3. Click edit in json
  4. look for 'python'
  5. change python -u to python3 -u