Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | os.getuid() and os.setuid() method
Next article icon

Get OS name and version in Python

Last Updated : 30 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Python programming has several modules that can be used to retrieve information about the current operating system and the version that is running on the system. In this article we will explore How to get the OS name and version in Python.

Let us see a simple example to get the OS name and version in Python.

Python
import os  print (os.name) 

Output
posix 

Explanation: The os module has an attribute name that tells the current OS running on the system. Depending on the OS the code is executed on, it will give the OS name. For example, when this code is running on Windows, it will return "nt" and when it is running on Unix-based system, it returns "posix".

Let us see other ways to get the OS name and version in Python.

Using Platform Module

The platform module in Python is used to retrieve the information about the platform on which the program is running. This module has various functions that can be used to get the information like the OS name and its version.

Using name()

name() function returns a tuple, which contains system name, name of the machine on the network, release, OS version and machine name.

Python
import platform   print(platform.uname()) 

Output
uname_result(system='Linux', node='6c42885e148b', release='5.15.0-1072-aws', version='#78~20.04.1-Ubuntu SMP Wed Oct 9 15:30:47 UTC 2024', machine='x86_64', processor='') 

Using system()

The system() function of the platform module gives the OS name and the version() function tells the current version of the OS installed on the machine.

Python
import platform  print("OS Name:", platform.system()) print("OS Version:", platform.version()) 

Output
OS Name: Linux OS Version: #78~20.04.1-Ubuntu SMP Wed Oct 9 15:30:47 UTC 2024 

Using sys Module

Python sys module can also be used to get the OS name and its version. The sys.platform gives a string value of the platform identifier. For Windows OS, it returns 'win32', for Linux, it returns 'linux', and for macOS, it returns 'darwin'.

Python
import sys  print("OS platform:", sys.platform) 

Output
OS platform: linux 

Next Article
Python | os.getuid() and os.setuid() method

T

tanyasehr88x
Improve
Article Tags :
  • Python
  • python-utility
  • python-os-module
Practice Tags :
  • python

Similar Reads

  • Python | os.geteuid() and seteuid() method
    All functions in the OS Module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system. os.geteuid() method in Python is used to get the current process’s effective user ID while os.seteuid
    3 min read
  • enchant.get_enchant_version() in Python
    Enchant is a module in python which is used to check the spelling of a word, gives suggestions to correct words. Also, gives antonym and synonym of words. It checks whether a word exists in dictionary or not. enchant.get_enchant_version() enchant.get_enchant_version() is an inbuilt method of enchant
    1 min read
  • Get Variable Name As String In Python
    In Python, getting the name of a variable as a string is not as straightforward as it may seem, as Python itself does not provide a built-in function for this purpose. However, several clever techniques and workarounds can be used to achieve this. In this article, we will explore some simple methods
    3 min read
  • Python | os.getuid() and os.setuid() method
    OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f
    3 min read
  • Python | os.getresgid() and os.setresgid() method
    OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f
    3 min read
  • Python | os.getegid() and os.setegid() method
    OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f
    2 min read
  • Python Tweepy - Getting the name of a user
    In this article we will see how we can get the name of a user. Name is the display name of the twitter account. It is the name that users choose to identify themselves on the network. Many users choose to either use their real name as the basis for their display name. Unlike screen names, the names
    2 min read
  • Check Version of Installed Python Modules
    In Python, it's important to keep track of the packages we're using. Knowing which version is installed can help avoid compatibility issues and make it easier to fix errors. This article discusses a few easy ways to check the version of any package in your Python environment. Let's explore them: Usi
    2 min read
  • Get tag name using Beautifulsoup in Python
    Prerequisite: Beautifulsoup Installation Name property is provided by Beautiful Soup which is a web scraping framework for Python. Web scraping is the process of extracting data from the website using automated tools to make the process faster. Name object corresponds to the name of an XML or HTML t
    1 min read
  • How to Download Python Old Version and Install
    Python is a popular programming language known for its simplicity and versatility. When we install Python in our systems we always install the latest version of it but there may be situations where we need to install an older version of Python due to compatibility reasons or to work on legacy projec
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences