简体   繁体   English

python3中platform.dist和platform.linux_distribution的替代方法是什么

[英]What is alternative of platform.dist and platform.linux_distribution in python3

It says here both Platform.dist() and platform.linux_distribution has been deprecated in version 3.5 and will be removed in version 3.7 (Current version 3.6.5 with 3.7 in preview mode). 它说这里的 Platform.dist()和platform.linux_distribution在3.5版中已被弃用并将在3.7版中删除 (当前版本3.6.5,预览模式为3.7)。 and I can't find any way around on how to find/get linux distro name in python3! 而且我找不到如何在python3中查找/获取linux发行版名称的方法!

Any way? 可以吗 Thanks in advance. 提前致谢。

I didn't search this a lot, but if you want the version informations, an easy way, maybe what python's platform.linux_distribution did anyway, would be to read files 我没有进行很多搜索,但是如果您想要版本信息,一种简单的方法,也许是python的platform.linux_distribution所做的,就是读取文件

/etc/*-release or /proc/version /etc/*-release/proc/version

and see what you can get from them. 看看你能从他们那里得到什么。 ^^' ^^'

So long that it's not in a performance-wise critical section of the code. 这么长的时间,它不在代码的性能关键部分。

Have a nice day! 祝你今天愉快!

After a small search, I found it here and it can be installed with pip install distro . 经过一番搜索,我在这里找到了它,可以使用pip install distro进行安装。 Then import distro instead of the import platform . 然后import distro而不是import platform

import distro 
print(distro.linux_distribution())

Output: 输出:

('Ubuntu', '18.04', 'Bionic Beaver')

I've tested in python versions 3.4, 3.5, 3.6, 3.7 and it's working perfectly. 我已经在python版本3.4、3.5、3.6、3.7中进行了测试,并且运行良好。

This pip package solves it. 这个点子包解决了。 [Not limited to python 3.7 issue] [不仅限于python 3.7问题]

https://github.com/nir0s/distro https://github.com/nir0s/distro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 platform.linux_distribution() 已弃用 - 有哪些替代方案? - platform.linux_distribution() deprecated - what are the alternatives? python平台库中的platform.linux_distribution返回(无,无,无) - platform.linux_distribution from the python platform library returns (None, None, None) platform.system和platform.linux_distribution到底输出什么? - What does platform.system and platform.linux_distribution exactly output? 为什么platform.linux_distribution()在一个操作系统上返回不同的结果? - Why does platform.linux_distribution() returns different results on one OS? pip3 错误:AttributeError:模块“平台”没有属性“linux_distribution”? (带有 python 3.8 的 ubuntu 20.04) - pip3 error : AttributeError: module 'platform' has no attribute 'linux_distribution'? (ubuntu 20.04 with python 3.8) Python应用分发跨平台 - Python app distribution cross-platform python3 strftime输出因平台而异 - python3 strftime output varies by platform 使用 Python3.8 安装新包时如何修复“模块‘平台’没有属性‘linux_distribution’”? - How to fix "module 'platform' has no attribute 'linux_distribution'" when installing new packages with Python3.8? python平台无法识别Ubuntu发行版 - python platform doesn't recognized Ubuntu distribution 分发跨平台python3脚本 - Distributing a cross platform python3 script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM