python - platform.linux_distribution() 已弃用 - 有哪些替代方案?

标签 python linux

自 Python 3.5 起platform.linux_distribution()已弃用,计划从 Python 3.7 中删除。

有什么我可以用来代替 platform.linux_distribution() 的吗?

platform.uname() 没有产生我需要的信息。我在 Docker 容器中运行代码,platform.uname() 返回主机的详细信息,而不是图像。

特别是,我正在构建一个 portable Linux distribution我想在规范的 CentOS 5.11 发行版上测试它。我正在寻找一种简单的方法来识别操作系统以识别/标记构建结果。

最佳答案

根据 Deprecated platform.linux_distribution() and platform.dist() , platform.linux_distribution() 将从 Python 3.7 中删除。它确实仍然存在于 Python 3.6 中。推荐的替代方案是 distro包。

安装包后,可以使用下面的代码。

import distro
distro.linux_distribution()

在较新版本的 distro 软件包中,distro.linux_distribution() 已被弃用。相反,该软件包提供了 distro.id()distro.version()distro.name()

关于python - platform.linux_distribution() 已弃用 - 有哪些替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49554443/

相关文章:

python - Django 3 'NoReverseMatch 在/post/1/

python - PDF - 设置密码保护打印、复制、粘贴选项?

linux - 相同代码的 Oprofile 和 gprof 输出不同

linux - 每个 cpu 变量的地址

python - 在python中绘制具有相同标签和颜色的序列

python - 安装 Tensorflow 警告 : Value for scheme. 脚本不匹配

linux - 对于成功执行的进程使用非零返回代码是否可以?

linux - 如何在 shell 脚本中使用 curl?

python - 确保用户在使用 BMI 分析器时只输入整数

linux - 通过 lame 增加几个 mp3 文件的音量