Search code examples
pythonpython-3.xbashpython-2.7sublimetext3

bash: python: command not found


I've recently installed Sublime text on Ubuntu. When I try to run some python code, the following error is popped up:

bash: python: command not found
[Finished in 0.0s with exit code 127]
[shell_cmd: python -u "/home/user/Desktop/Python Project/test.py"]
[dir: /home/user/Desktop/Python Project]
[path: /home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

when I run python on the commandline, I get:


  command 'python3' from deb python3
  command 'python' from deb python-is-python3

When I run python3 on the commandline, I get:

Python 3.8.2 (default, Apr 27 2020, 15:53:34) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Solution

  • The Sublime Text is configuring python instead of python3. You just need to add a new build system to the Sublime Text. To do that, Select Tools > Build System > New Build System... Now, a new file will open. Add the following code to this file:

    {
        "cmd": ["/usr/bin/python3", "-u", "$file"],
        "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
        "selector": "source.python"
    }
    

    Now, save the file as Python3.sublime-build. Now, change you Build System to Python3 and try to run you code again. Now, it should run successfully.