我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
我必须在Windows服务器上运行Python脚本。我怎么知道我用的是哪个版本的Python,这真的很重要吗?
我在考虑升级到最新版本的Python。
当前回答
在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'
其他回答
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)'
有两种简单的方法来检查安装的Python版本。
运行命令提示符上的任意代码:
python -v
or
python --version
只需创建一个以.py结尾的文件,并将下面的代码粘贴进去并运行它。
#!/usr/bin/python3.6
import platform
import sys
def linux_dist():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_dist(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
))
当系统中安装了多个Python解释器版本时,执行以下命令。
在Linux操作系统中,在终端中运行:
ll /usr/bin/python*
在Windows操作系统中,在命令提示符中运行:
dir %LOCALAPPDATA%\Programs\Python
在带有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)]