我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
当前回答
对我来说,打开CMD并运行
py
会显示一些东西
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
其他回答
如果你安装了Python,那么检查版本号最简单的方法是在命令提示符中输入“Python”。它将显示版本号,以及它是运行在32位还是64位以及其他一些信息。对于某些应用程序,您可能希望使用最新版本,但有时不需要。这取决于您想要安装或使用什么包。
主要是使用命令:
python -version
Or
python -V
Windows下Python的默认版本和所有已安装版本的路径:
py -0p
一行程序:
❯❯ python -V | cut -c8-
3.11.0
❯❯ ~ python -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python --version
Python 3.11.0
❯❯ ~ py --list
-V:3.11 * Python 3.11 (64-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.9 Python 3.9 (64-bit)
❯❯ ~ py -V
Python 3.11.0
❯❯ ~ py -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ py --version
Python 3.11.0
❯❯ ~ py -0p
-V:3.11 * W:\Windows 10\Python311\python.exe
-V:3.10 W:\Windows 10\Python310\python.exe
-V:3.9 C:\Program Files\Python39\python.exe
❯❯ ~ python -c 'import sys; print(".".join(sys.version.split(".")[0:2]))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version)'
3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python -c 'import sys; print((str(sys.version_info.major) +"."+ str(sys.version_info.minor)))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version_info)' sys.version_info(major=3, minor=11, micro=0, releaselevel='final', serial=0)
❯❯ ~ python -c 'import platform; print(platform.python_version()[:-2])'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version())'
3.11.0
❯❯ ~ python -c 'import platform; print("{0[0]}.{0[1]}".format(platform.python_version_tuple()))'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version_tuple())'
('3', '11', '0')
python -V
http://docs.python.org/using/cmdline.html#generic-options
——version也可以工作(在2.5版本中引入)
Python 2.5 +:
python --version
Python 2.4 -:
python -c 'import sys; print(sys.version)'