解决 Bash 中的 Python3 命令未找到错误

Yahya Irmak 2023年1月30日
  1. 在 Linux 上安装 python3
  2. 解决 Bash 中的 python3 command not found 错误
解决 Bash 中的 Python3 命令未找到错误

Python 是一种高级的通用编程语言。它有两个主要版本,Python 2.x 和 Python 3.x。

本文将解释如何安装 Python3 并解决 Linux Bash 中的 bash: python3: command not found 错误。

在 Linux 上安装 python3

必须在你的计算机上安装官方 Python 工具才能执行使用 Python 编程语言创建的程序。python3 工具可以使用以下命令安装在 Linux 发行版上。

为 Arch Linux 安装 python3 工具。

sudo pacman -S python

为 Ubuntu 和 Debian 安装 python3 工具。

sudo apt-get install python3

为 Fedora 安装 python3 工具。

sudo dnf install python3

除此之外,python3 工具可以手动安装。使用 curl 工具从官方存储库下载文件并将其保存为 Python-3.10.2.tar.xz

curl https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz -o Python-3.10.2.tar.xz

提取文件内容。

tar -xvf Python-3.10.2.tar.xz

导航到 Python-3.10.2 目录并执行配置文件。然后使用 make 命令。

cd Python-3.10.2
./configure
make
make install

你可以通过从这些选项中选择最适合你的工具来成功安装 python3 工具。现在你可以使用 python3 programname 命令执行你想要的程序。

解决 Bash 中的 python3 command not found 错误

如果在执行 Python 程序时遇到 bash: python3: command not found 错误,你可能使用了错误的版本。首先,检查系统上安装的 Python 版本以解决问题。

python3 --version
python2 --version
python --version

Python–版本

通常,python 与 Python 2.x 一起使用,python3 与 Python 3.x 一起使用。如果你想执行 Python3 程序,请尝试输入 python3 而不是 python

python3 programname

如果你的系统上安装了 Python3,你将能够以这种方式成功运行程序。但是,如果你不想每次都输入 python3,你可以在 .bashrc 文件中添加一个别名。

alias python="python3"

因此,你只需键入 python 即可执行 Python3 程序。

作者: Yahya Irmak
Yahya Irmak avatar Yahya Irmak avatar

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

LinkedIn

相关文章 - Bash Error