How To Check The Python Version In A Python IDE

Knowing which version of Python you are using is essential as it helps you determine whether your code will run correctly on a particular Python setup. This tutorial will guide you on how to check the Python version in a Python IDE (Integrated Development Environment).

Step 1: Select an IDE you want to use

Find the Python IDE you feel most comfortable using. Some popular Python IDEs include:

  1. PyCharm
  2. Visual Studio Code
  3. Jupyter Notebook
  4. Atom
  5. Sublime Text

For this tutorial, I’ll demonstrate how to check the Python version in a Jupyter Notebook, but the steps should be similar for other IDEs.

Step 2: Create a new Python file

Create a new Python file or open an existing one in your preferred IDE. If you’re using Jupyter Notebook, create a new notebook by clicking on “New” from the file menu and selecting “Python 3” to open a new notebook.

Step 3: Check Python version using the sys module

To check the Python version, you need to import the sys module. The sys module provides access to some variables used or maintained by the interpreter, such as the Python version.

In your Python file, write the following code to import the sys module and print the Python version:

Alternatively, you can print only the version_info attribute of the sys module, which contains a tuple of the major, minor, and micro-release numbers.

Step 4: Run the code and check the Python version

Now, run your code to check the Python version. If you’re using Jupyter Notebook, click on the cell containing your code and press Shift + Enter to run the cell.

The output of your code should be the current Python version installed and being used by the IDE.

Python code:

Output:

3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0]
sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)

As you can see in the output, the Python version being used in this example is 3.8.5.

Conclusion

In conclusion, checking the Python version in a Python IDE is an easy process that helps you determine compatibility and ensure your code runs smoothly. By using the sys module, you can quickly and easily check the Python version being used by your IDE, allowing you to write and run code knowing you are on the right version.