如何找到Python版本?

我想运行一些python脚本,但想学习系统上安装的python版本。我该怎么做?这几乎适用于从Windows到Linux,从macos到Bsd的所有操作系统。

null

获取默认Python解释器的版本

我们可以得到默认的python解释器版本,如下所示。我们知道,如果没有指定python的版本,那么将调用默认的python解释器。

$ python -V

或者

$ python --version
Get Version Of Default Python Interpreter
获取默认Python解释器的版本

我们可以从输出中看到当前或默认的Python解释器版本是 2.7

获取Python2精确版本

我们可以得到Python2的精确版本,如下所示

$python2 -V Python 2.7.12+ $python2 --version Python 2.7.12+

获取Python3精确版本

我们可以得到Python2的精确版本,如下所示

$python3 -V Python 3.5.2+ $python3 --version Python 3.5.2+
Get Python3 Exact Version
获取Python3精确版本

使用sys.version信息

Python提供 version 中的属性 sys 模块。我们可以使用此属性以交互方式或编程方式获取Python版本。

import sysprint(sys.version)
Using sys.version Information
使用sys.version信息

更新Python解释器版本

如果我们想更新Python解释器,我们通常使用发行版提供的包管理器。

Ubuntu、Debian、Mint、Kali

$ sudo apt update python

软呢帽、CentOS、RedHat

$ sudo yum update python

或者

$ sudo dnf update python

如何找到Python版本?信息图

How To Find Python Version? Infografic
如何找到Python版本?信息图

相关文章: 什么是Fedora(Linux操作系统/发行版)?

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享