Python

Module ‘os’ has no attribute ‘uname’ ( Solved )

OS module is a python module that allows you to interact with the operating systems. It uses various functions to interact with the operating system. Using it you can automatically tell the python interpreter to know which operating system you are running the code. But while using this module function sometimes you get AttributeError.  The AttributeError: module ‘os’ has no attribute ‘uname’ is one of them.

In this entire tutorial, you will learn how to solve the issue of module ‘os’ has no attribute ‘uname’ easily.

The root cause of the module ‘os’ has no attribute ‘uname’ Error

The root cause of this attributeError is that you must be using the uname() function wrongly. The import part of the os module is right but the way of using the uname() is wrong.

If you will use os.uname() on your Windows OS then you will get the error.

import os
print(os.uname())

Output

os has no attribute uname error

Solution of the module ‘os’ has no attribute ‘uname’

The solution of the module ‘os’ has no attribute ‘uname’ is very simple. You have to properly use the uname() method. If your operating system is Unix then its okay to use os.uname().

But in case you are using the Windows operating system then import platform instead of import os. In addition call platform.uname() instead of os.uname().

You will not get the error when you will run the below lines of code.

import platform
print(platform.uname())

Output

System Information using the function uname

Conclusion

OS module is very useful if you want to know the system information. But there are some functions that lead to attributerror as that function may not support the current Operating system.

If you are getting the  ‘os’ has no attribute ‘uname’ error then the above method will solve your error.

I hope you have liked this tutorial. If you have any queries then you can contact us for help. You can also give suggestions on this tutorial.