[英]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.