Back to Python
2026-03-115 min read

Step 2: Check Python Version

Learn Step 2: Check Python Version step by step with clear examples and exercises.

Why This Matters

Knowing your Python version is essential for several reasons:

  1. Compatibility: Compatibility issues can arise when using libraries and packages that require specific Python versions. By knowing your Python version, you can ensure that the libraries you use are compatible with your current setup.
  1. Efficiency: Different Python versions offer various features and improvements. Understanding the features available in different versions can help you write more efficient code and take advantage of these advancements.
  1. Troubleshooting: Version-specific bugs or incompatibilities can cause issues in your code. Knowing your Python version helps you identify and resolve such problems more effectively.

Prerequisites

Before diving into checking Python versions, make sure you have a basic understanding of:

  1. How to install and uninstall Python on your system (e.g., using package managers like apt-get, brew, or chocolatey).
  2. Navigating the command line or terminal (e.g., using commands like cd, ls, and pwd).
  3. Basic Python syntax and variables (e.g., understanding data types, loops, and functions).

Core Concept

To check the Python version, open your terminal or command prompt and type the following command:

python --version

Upon executing this command, you'll see a message displaying the Python version installed on your system. For example:

Python 3.8.5

If you have multiple versions of Python installed, you can switch between them using the python3 and python commands. The python3 command will use the most recent version, while the python command allows you to specify a particular version by providing its path.

For instance, if you have both Python 3.8 and Python 3.9 installed, and you want to use Python 3.9, navigate to the directory containing the Python 3.9 executable (usually located in /usr/bin or C:\Python39) and run:

python3.9 -m venv my_project

This command creates a new virtual environment named "my_project" using Python 3.9. To activate the virtual environment, navigate to its directory and execute:

source bin/activate

Now, when you run python --version, it will show that you're using Python 3.9 within the virtual environment.

Creating a Virtual Environment with Specific Python Version

If you have multiple Python versions installed but want to create a virtual environment using a specific version, navigate to the directory containing the desired executable and use its name when creating the virtual environment:

cd /usr/bin
python3.8 -m venv my_project_3.8

This command creates a new virtual environment named "my_project_3.8" using Python 3.8. To activate it, navigate to the bin directory and execute:

source my_project_3.8/bin/activate

Worked Example

Let's verify the Python version on a Linux system:

  1. Open the terminal and type:
python --version
  1. The output will display the current Python version, for example:
Python 3.8.5

Now that you know your system's Python version, let's create a new virtual environment using Python 3.9 and activate it:

  1. Navigate to the directory containing the Python 3.9 executable (usually located in /usr/bin):
cd /usr/bin
  1. Create a new virtual environment named "my_project":
python3.9 -m venv my_project
  1. Navigate into the newly created virtual environment:
cd my_project/bin
  1. Activate the virtual environment:
source activate
  1. Verify that the activated Python version is 3.9 by running:
python --version

The output should display:

Python 3.9.2

Common Mistakes

  1. Not specifying the Python version: When using multiple versions of Python, always ensure you're working with the correct one by providing the specific version number or navigating to its directory before executing commands.
  1. Incorrect path to the Python executable: If you have multiple Python installations, make sure you're using the correct path when creating virtual environments or running scripts.
  1. Not activating the virtual environment: When working within a virtual environment, always activate it before running your Python commands to ensure they use the intended version of Python.
  1. Not deactivating the virtual environment: Remember to deactivate the virtual environment when you're done working with it by simply typing:
deactivate

Practice Questions

  1. You have both Python 3.7 and 3.8 installed on your system. How can you verify that you're using Python 3.8 in a new virtual environment?

Answer: Navigate to the directory containing the Python 3.8 executable, create a new virtual environment, activate it, and run python --version within the activated environment.

  1. You are working on a project that requires Python 3.9, but your system only has Python 3.8 installed. What steps should you follow to create a virtual environment with Python 3.9 and activate it for your project?

Answer: Navigate to the directory containing the Python 3.9 executable (if available), create a new virtual environment, activate it, and ensure that the activated Python version is 3.9 by running python --version. If the Python 3.9 executable is not available, you may need to reinstall or upgrade your Python installation.

FAQ

  1. Why do I need to check my Python version? Knowing the Python version helps ensure compatibility with libraries and packages, understand available features, and troubleshoot issues caused by version-specific bugs or incompatibilities.
  1. How can I switch between multiple versions of Python on my system? To switch between Python versions, use the python3 and python commands along with specifying the desired version number or navigating to its directory.
  1. What is a virtual environment, and why should I create one? A virtual environment isolates your project from the global Python installation, allowing you to manage dependencies for that specific project without affecting other projects on your system. This helps prevent conflicts between libraries with incompatible versions or requirements.
  1. How can I deactivate a virtual environment? To deactivate a virtual environment, simply type:
deactivate

This command exits the activated virtual environment and returns you to your global Python installation.

Step 2: Check Python Version | Python | XQA Learn