Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'os' has no attribute 'uname

When I do:

>>> import os
>>> os.uname()

I get an attribute error which looks like this:

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

How can I fix this is my python broken or something else because in the docs. Thank you in advanced.

like image 939
Jimmy Lin Avatar asked Apr 16 '20 01:04

Jimmy Lin


2 Answers

I've run your code the exact same way in IDLE on Windows 10 and got the same result.

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

And as @Joran Beasley pointed out, this function is only available in certain operating systems.

From an online compiler:

posix.uname_result(sysname='Linux', nodename='Check', release='5.4.10-x86_64-linode132', version='#1 SMP PREEMPT Thu Jan 9 21:17:12 UTC 2020', machine='x86_64')

If you want to get current os, I recommend the platform module.

>>> import platform
>>> platform.platform()
'Windows-10-10.0.18362-SP0'

Some people prefer using os module, but platform is much more readable.

like image 92
Cheng An Wong Avatar answered Sep 28 '22 07:09

Cheng An Wong


Unfortunately, the uname function only works on some Unix systems. If you are on Windows, you can use the uname function in the platform module, which returns a similar result.

>>> import platform
>>> print(platform.uname())
uname_result(system='Windows', node='DESKTOP-OVU16P3', release='10', version='10.0.19042', machine='AMD64')
like image 29
user16574925 Avatar answered Sep 28 '22 07:09

user16574925