我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
当前回答
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')
其他回答
Use
python -V
or
python --version
注意:请注意python -V命令中的“V”是大写V。python -V(小“V”)将以verbose模式启动python。
可以使用以下命令获取Python版本
python --version
你甚至可以使用pip freeze as获得安装在venv中的任何软件包的版本:
pip freeze | grep "package name"
或者使用Python解释器:
In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)
在带有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)]
主要是使用命令:
python -version
Or
python -V
我在Windows 10上安装了Python 3.7.0。
这是我在命令提示符和Git Bash中工作的方法:
使用实例运行Python并查看版本。
py
只检查您拥有的版本:
py --version
or
py -V # Make sure it is a capital V
注意:python, python——version, python -V, python, python——version, python -V不适合我。