【问题标题】:os.uname() module of python not working in windows but in wsl 2 (ubuntu 20.04)python的os.uname()模块在windows中不工作,但在wsl 2(ubuntu 20.04)
【发布时间】:2020-07-08 15:30:47
【问题描述】:

当我在 WSL2(ubuntu 20.04) 中用 python 编写代码时:

>>import os
>>os.uname()

输出是:

posix.uname_result(sysname='Linux', nodename='Saqib-PC', release='4.19.104-microsoft-standard', version='#1 SMP Wed Feb 19 06:37:35 UTC 2020', machine='x86_64')

但是当我在 Windows 终端上运行相同的代码时,它给了我一个 AttributeError:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'os' has no attribute 'uname'

这里给出了 Windows 终端和 WSL2 中的截图:

在 Windows 终端中: see image here

在 WSL2(Ubuntu 20.04)中: see image here

顺便说一句:其他操作系统模块的工作文件在两者中


谁能告诉我为什么会这样?

【问题讨论】:

    标签: python windows-terminal wsl-2


    【解决方案1】:

    os.uname 仅适用于 Unix 发行版/版本的子集:。

    来自docs

    可用性:最新的 Unix 版本。

    不涉及技术细节,WSL 仍然是 Unix,就像 Windows 主机上的 Linux VM“仍然”是 Unix(因此,os.uname 将在那里可用)。

    【讨论】:

    • 谢谢我知道了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 2021-04-13
    • 2021-10-26
    • 2021-06-01
    • 1970-01-01
    • 2020-09-03
    • 2021-08-06
    相关资源
    最近更新 更多