Linux how to find python version

How to Check Python Version for Mac, Windows, and Linux

Web developers, engineers, and other software professionals need to know how to check Python version installed on their machines. Although the process is simple, some beginners may find it hard to figure out how to check Python version.

If you’re new to Python, we suggest taking a Python course to become familiar with the syntax and subtleties of the language.

In this article, we’ll guide you through a few easy steps to check Python version on your Mac, Windows, or Linux machine. All you need to begin is a computer with a Python release installed.

What is Python?

Python is a programming language used in web development, machine learning, and automation tasks. It is object-oriented, interpreted, and has a clear, simple syntax that makes it easy to learn and use.

It is one of the most popular and widely used languages, rivaling Javascript, Java, and C.

Python’s core library is extensive and freely distributed. These libraries and packages extend Python’s standard functionality.

The #1 Reason You Need to Know How to Check Python Version

There are many different versions of Python, and each version operates slightly differently with other dependencies and packages you have installed. Therefore, it’s crucial to ensure you have the correct version of Python installed to support the other dependencies in your project.

It is possible to have more than one version of Python installed on your computer. If you are a serious developer, you might simultaneously work on several applications requiring different Python versions.

For this reason, developers often run Python inside a virtual environment. In addition, it’s common to run a separate virtual environment for each Python project you work on.

A virtual environment is like a virtual machine that runs on your computer and keeps all the Python interpreters, versions, packages, dependencies, and scripts isolated from other Python projects on your computer.

Источник

How to Check Python Version in Linux, Mac, & Windows

Python is a popular programming language. Like many other programming languages, there can be several different versions organized by release date. Certain applications may require a specific version of Python.

Читайте также:  Html css align image with text

In this tutorial, learn how to check the Python version on Windows, Linux, or macOS systems.

tutorial on how to check Python version.

Access to a command-line/terminal window:

  • Linux: Ctrl-Alt-T, Ctrl-Alt-F2
  • Windows: Win+R > type powershell > Enter/OK
  • MacOS: Finder > Applications > Utilities > Terminal

There are different versions of Python, but the two most popular ones are Python 2.7.x and Python 3.7.x. The x stands for the revision level and could change as new releases come out.

When looking at the version number, there are usually three digits to read:

While major releases are not fully compatible, minor releases generally are. Version 3.6.1 should be compatible with 3.7.1 for example. The final digit signifies the latest patches and updates.

Python 2.7 and 3.7 are different applications. Software that’s written in one version often will not work correctly in another version. When using Python, it is essential to know which version an application requires, and which version you have.

Python 2 will stop publishing security updates and patches after 2020. They extended the deadline because of the large number of developers using Python 2.7. Python 3 includes a 2 to 3 utility that helps translate Python 2 code into Python 3.

How to Check Python Version in Linux

Most modern Linux distributions come with Python pre-installed.

To check the version installed, open a terminal window and entering the following:

python version linux

How to Check Python Version in Windows

Most out-of-the-box Windows installations do not come with Python pre-installed. However, it is always a good idea to check.

Open Windows Powershell, and enter the following:

If you have Python installed, it will report the version number.

check python version windows

Alternately, use the Windows Search function to see which version of Python you have:

Press the Windows key to start a search, then type Python. The system will return any results that match. Most likely a match will show something similar to:

This defines which major and minor revision (3.x or 2.x) you are using.

How to Check Python Version in MacOS

If using a MacOS, check the Python version by entering the following command in the terminal:

The system will report the version.

check python version macos

Note: In some cases, this will return a screen full of information. If that happens, just scan through the file locations for the word python with a number after it. That number is the version.

Checking a System with Multiple Versions of Python

Python2 and Python3 are different programs. Many programs upgrade from the older version to the newer one. However, Python 2.7.x installations can be run separately from the Python 3.7.x version on the same system.

Читайте также:  Html input передача значения

Python 3 is not entirely backward compatible.

To check for Python 2.7.x:

To check the version of Python 3 software:

Most systems differentiate Python 2 as python and Python 3 as python3. If you do not have Python 2, your system may use the python command in place of python3 .

Note: Python does not have a built-in upgrade system. You’ll need to download the latest version and install it.

How to Check Python Version in Script

When writing an application, it is helpful to have the software check the version of Python before it runs to prevent crashes and incompatibilities.

Use the following code snippet to check for the correct version of Python:

if not sys.version_info.major == 3 and sys.version_info.minor >= 6: print("Python 3.6 or higher is required.") print("You are using Python <>.<>.".format(sys.version_info.major, sys.version_info.minor)) sys.exit(1)

When this script runs, it will test to see if Python 3.6 is installed on the system. If not, it will send a notification and displays the current Python version.

Note: One of the common issues in working with Python and datasets is missing data. Learn how to handle missing data in Python.

You should now have a solid understanding of how to check for the version of Python installed in several different operating systems. Python is a powerful programming language, thus it’s important to understand its different versions.

If you want to learn how to upgrade Python to a newer version on Wondows, macOs, and Linux, check our article how to upgrade Python to 3.9.

Источник

3 Ways to Check Python Version in Linux

How to get the Python version on Linux is a commonly asked question during a Linux job interview. In this article, we will cover 3 ways to find the Python version in Linux.

We will learn how to check the python version using the python command as well as how to determine the python version programmatically, from the python console and using python script.

Understanding Python Version

Python is a high-level, general-purpose programming language created by Guido van Rossum. It was first released in 1991. Generally, Linux based distros have pre-installed Python version.

Before we can check what version of Python our computer has loaded, we must understand the version scheme of Python. Every Python version has three digits.

The first digit represents the major version, the second the minor version, and the third digit represents the micro version or “revision level.”

For example, in Python 3.6.8, 3 is a major version, 6 is a minor version, and 8 is a micro version.

We must also note that major versions are typically not fully compatible with each other. In other words, software written with Python version 2.x.x may not run correctly with Python 3.x.x. However, minor releases are typically compatible with the previous releases. For example, code written in Python 3.1.x will run with Python 3.10.x (which is the current Python version).

Читайте также:  Define logging in java

Python Version release

Python 3.0, a major, backwards-incompatible release, was released on December 3, 2008 after a long period of testing. Many of its major features have also been backported to the backwards-compatible, though now-unsupported, Python 2.6 and 2.7.

3 Ways to check Python version in Linux

The following commands can be used to get Python version in Linux.

  • python3 –version or python -V or python -VV
  • python3 -c “import sys; print(sys.version)”
  • python3 -c “import sys; print(sys.version_info)”
  • python3 -c “import platform; print(platform. python_version())”

Check Python version in Linux with python -V command

To check Python version in Linux, you can use python -V command. All you need is to open the terminal then type python -V in the prompt. The Python version will be listed. In some environments, the Python2.x series is assigned to python command, and the Python3.x series is assigned to python3 command.

  • $ python –version
    Python 2.7.15
  • $ python -V
    Python 2.7.15
  • $ python3 –version
    Python 3.7.0
  • $ python3 -V
    Python 3.7.0

Check Python version with sys module in Linux

The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. We can use sys.version to return a string containing the version of Python Interpreter with some additional information.

$ python3 -c “import sys; print(sys.version)”
3.6.8 (default, Mar 18 2021, 08:58:41)
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

$ python3 -c “import sys; print(sys.version_info)”
sys.version_info(major=3, minor=6, micro=8, releaselevel=’final’, serial=0)

Check Python version with platform module in Linux

The platform module in Python is used to access the underlying platform’s data, such as, hardware, operating system, and interpreter version information.

platform.python_version() returns a string major.minor.patchlevel. It is useful when we want to get the version number as a simple string.

$ python3 -c “import platform; print(platform.python_version())”
3.6.8

$ python3 -c “import platform; print(platform.python_version_tuple())”
(‘3’, ‘6’, ‘8’)

We can also get more info with Python platform module.

  • platform.architecture()
    returns information about the bit architecture
  • platform.machine()
    returns the machine type, e.g. ‘i386’.
  • platform.node()
    returns the computer’s network name (may not be fully qualified!)
  • platform.platform()
    returns a single string identifying the underlying platform with as much useful
    information as possible.

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

howtouselinux.com is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative.

Источник

Оцените статью