首页 > 解决方案 > bash:python:找不到命令

问题描述

我最近在 Ubuntu 上安装了 Sublime text。当我尝试运行一些python代码时,会弹出以下错误:

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]

当我 python在命令行上运行时,我得到:


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

当我 python3 在命令行上运行时,我得到:

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.

标签: pythonpython-3.xbashpython-2.7sublimetext3

解决方案


Sublime Text 正在配置 python 而不是 python3。你只需要在 Sublime Text 中添加一个新的构建系统。为此,选择Tools> Build System>New Build System... 现在,将打开一个新文件。将以下代码添加到该文件中:

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

现在,将文件另存为Python3.sublime-build. 现在,将您更改Build SystemPython3并尝试再次运行您的代码。现在,它应该可以成功运行。


推荐阅读