geekdoc-python-zh/docs/pythonland/59.md

29 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 在命令行上检查 Python 版本
> 原文:[https://python . land/migrating-from-python-2-to-3/how-to-check-your-python-version](https://python.land/migrating-from-python-2-to-3/how-to-check-your-python-version)
不确定您运行的是哪个 Python 版本?在这篇简短的操作指南中,您将学习如何检查您的 Python 版本。你不想无意中运行一个旧版本,即使你刚刚安装了最新版本!是的,会发生这种情况。检查 Python 版本很容易,我们就这么做吧。
## 检查 Python 版本
这个简单的命令适用于所有操作系统,包括 Windows、Linux 和 MacOS。假设您已经安装了[Python](https://python.land/installing-python),并且[终端打开了](https://python.land/installing-python/starting-python),那么您可以使用下面的命令检查您当前的 Python 版本:
```py
$ python --version
Python 2.7.16
```
希望你的版本是 3.7.x 或者更高。但是如果上面写的是 2.7.x(或者更低),现在还不用担心。
Python 长期以来有两个版本:版本 2 和版本 3。正如我们在关于 [Python 的历史](https://python.land/python-tutorial/python-history)的文章中所解释的,它们是并存的。
在许多系统上,安装了两个版本的 Python。当某些软件需要版本 2而操作系统或用户也需要版本 3 时,就会出现这种情况。在这种情况下,通常,当您输入`python`时 Python 2 运行,当您输入`python3`时 Python 3 运行。
让我们再次检查 Python 版本,但现在尝试使用 python3:
```py
$ python3 --version
Python 3.7.6
```
如果您的输出看起来相似,那么恭喜您。您已经安装了 Python 3如果没有请按照[中的步骤为您的操作系统安装 Python 3](https://python.land/installing-python) 。