gpt4 book ai didi

python - 确定 python 是否正在 Ubuntu Linux 中运行

转载 作者:IT王子 更新时间:2023-10-29 00:06:26 25 4
gpt4 key购买 nike

我有一个像这样运行的 Python 3.2 程序:

import platform
sysname = platform.system()
sysver = platform.release()
print(sysname+" "+sysver)

在 Windows 上它返回:

Windows 7

但在 Ubuntu 和其他系统上它返回:
Linux 3.0.0-13-通用

我需要这样的东西:

Ubuntu 11.10 或 Mint 12

最佳答案

看起来 platform.dist()platform.linux_distribution()deprecated in Python 3.5 and will be removed in Python 3.8 .以下适用于 Python 2/3

import platform
'ubuntu' in platform.version().lower()

示例返回值

>>> platform.version()
'#45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022'

关于python - 确定 python 是否正在 Ubuntu Linux 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8338739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com