![]() ![]() Check Python version with platform module in Linux.Check Python version with sys module in Linux.Check Python version in Linux with python -V command.3 Ways to check Python version in Linux.Being able to check the version of Python you’re using allows you to better troubleshoot your code and identify any problems that are caused by versions. You also learned how to check the version your code is running in your script using both the sys and platform library. In this tutorial, you learned how to check your version of Python on Windows, macOS and Linux. Let’s take a look at an example: # Checking Your Python Version with platform Unlike the sys library, the tuple that’s returned is not a named tuple and each item in the tuple is a string, not an integer. Similar to the sys library, the platform library provides a way to extract a tuple. Let’s see how we can import the library and return a string containing our current Python version: # Checking Your Python Version with platform For example, the python_version() function can be used to return a string that contains the Python version. The Python platform library provides a number of helpful methods that are very similar to the ones provided by the sys library. How to Check Your Python Version in a Script Using platform In the next section, you’ll learn how to use the platform library to check your Python version. In the code above we checked if our system was capable of running Python f-strings. If sys.version_info.major = 3 and sys.version_info.minor >= 6: Let’s see how we can check the major and minor version to see if we can use Python f-strings: # Checking the Python Version Number Programatically The tuple returned has the following attributes: (major, minor, micro, releaselevel, serial). It returns a named tuple that provides all the information in an easy to access manner. python_version attribute to make this process better. ![]() For example, if you wanted to check whether or not a script is running in Python 3.6 or later (to make use of f-strings, for example), you’d have a hard time parsing this. Let’s take a look: # Checking the Python Version Using the sys libraryīecause this returns a multi-line string, it’s not immediately accessible. This returns the same information as the -VV command shown above. One of the simplest ways is to simply print out the. The sys library provides a number of different ways in which you can access the version of Python you’re running. How to Check Your Python Version in a Script Using sys In the next sections, you’ll learn how to check the version of Python your code is running in your script using the sys and platform libraries. The table below breaks down the different commands to run on macOS and Linux to get the version of Python: Commandĭifferent commands to check your Python version on macOS and Linux Because of this, you may need to run python3 instead, to refer to that version of Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |