我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?

我在考虑升级到最新版本的Python。


当前回答

Python 2.5 +:

python --version

Python 2.4 -:

python -c 'import sys; print(sys.version)'

其他回答

在带有Python 3.9.1的Windows 10上,使用命令行:

    py -V

Python 3.9.1

    py --version

Python 3.9.1

    py -VV

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit 
(AMD64)]

打开一个命令提示窗口(按Windows + R,键入cmd,并按Enter)。

类型python.exe

主要是使用命令:

python -version

Or

python -V

在Windows操作系统下,在命令提示符中输入以下命令,验证命令的Python版本。

c:\> python -V
Python 2.7.16

c:\> py -2 -V
Python 2.7.16

c:\> py -3 -V
Python 3.7.3

此外,要查看每个Python版本的文件夹配置,请运行以下命令:

For Python 2, 'py -2 -m site'
For Python 3, 'py -3 -m site'
>>> import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))
3.5

从命令行开始:

python -c "import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))"