python - 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.
解决方案
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 System
为Python3
并尝试再次运行您的代码。现在,它应该可以成功运行。
推荐阅读
- azure-functions - 如何在azure cosmos db中选择数千个关注用户的帖子?
- javascript - 使用 Google Scrips 和 Regex 返回匹配列
- javascript - 展平对象并将多个对象推送到数组
- python - 使用 for 循环编辑列表
- javascript - 在使用 .fetch 时,我可以将现有的 .fetch 函数链接到更大的同步查询中吗?
- javascript - typeof 返回对象但出现错误:“未定义不是对象”
- swift - 如何存储弹出或关闭的 ViewController 的变量值
- python - 模型表格不显示
- heroku - 我如何与其他 Salesforce 用户共享我与 Heroku 连接的数据
- docker - 无法从 Postman 的 k8s-Skaffold 中获得 Express API 的响应