python命令就可以检测是否安装了 Python,以及安装了哪个版本,如下所示:
[c.biancheng.net@localhost ~]$ python Python 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>可以看到,
python命令能够正常运行,并输出了 Python 的版本信息,这表明当前的 Linux 发行版已经自带了 Python 2.7.5。>>>,这意味着我们进入了 Python 交互式编程环境,可以在这里直接输入代码并查看运行结果,如下所示:
[c.biancheng.net@localhost ~]$ python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("C语言中文网的网址是:http://c.biancheng.net")
C语言中文网的网址是:http://c.biancheng.net
>>> a=100
>>> b=4
>>> a*b
400
>>> exit()
[c.biancheng.net@localhost ~]$
exit() 用来退出 Python 编程环境,回到 Linux 命令行。python3命令,如下所示:[c.biancheng.net@localhost ~]$ Python3 Python 3.6.4 (default , Nov 18 2018 , 13:02:36) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2 Type "help","copyright","credits" or "license" for more information. >>>如果
python3命令运行成功,并出现 Python 提示符>>>,则表明当前 Linux 发行版已经安装了 Python 3 开发环境,只需执行python3命令就可以启动 Python 3 开发环境。
$sudo apt-get update
$sudo apt-get install python3.8
python3命令,就可以看到 Python 交互式编程环境已经更新到 Python 3.8。
.tgz格式的源码压缩包地址。$ wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
解压源码包:$ tar -zxvf Python-3.8.1.tgz
$ ./configure --prefix=/usr/local
$ make&&sudo make install
--prefix=/usr/local用于指定安装目录(建议指定)。如果不指定,就会使用默认的安装目录。python命令默认调用的是 Python 2.x 开发环境,如果你习惯使用 Python 3.x,感觉每次输入python3命令有点麻烦,那么你可以修改配置,让python命令转而调用 Python 3.x 开发环境。具体命令如下:
$sudo unlink /usr/bin/python
$sudo ln -s /usr/bin/python3.8 /usr/bin/python
python命令,进入的就是 Python 3.8 的交互式开发环境了。
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有