How to Downgrade Python on Windows, macOS, and Linux

目次

1.Why you may need to downgrade Python

Python is a language widely used for programming and data science, but sometimes you need to use a specific version. You may need to downgrade for reasons like the following:
  • Library and tool compatibility issues Some libraries or frameworks may only support certain Python versions. For example, older versions of TensorFlow may only work on Python 3.9 or earlier.
  • Project requirements When working in a team, you may be required to use the same Python version across the entire project.
  • Ensuring stability If a new version has just been released, it may lack stability, so you may prefer to use an older version that is already stable.
This article explains concrete procedures to downgrade Python versions on Windows, macOS, and Linux. We’ll also cover flexible version management using virtual environments and discuss important considerations when downgrading.

2. How to check your current Python version

Importance of Checking Your Current Python Version

Before downgrading Python, it’s important to check which version is currently installed. This helps you understand the state of Python on your system and ensures you can switch without issues. Also, because environment variables and virtual environments can cause multiple versions to coexist, this verification step is essential.

Checking Python Version from the Command Line

The main way to check your Python version is by using the command line (terminal). Below are steps for each OS.

How to Check Python Version on Windows

  1. Open Command Prompt
  • Press the Windows key, type “cmd”, and select “Command Prompt”.
  1. Enter the command to check Python version Type one of the following:
   python --version
or
   python3 --version
  1. Check the output Example:
   Python 3.11.5

How to Check Python Version on macOS

  1. Open Terminal In Finder, choose “Applications > Utilities > Terminal”.
  2. Enter the command to check Python version
   python3 --version
  1. Check the output On macOS, a system-default Python 2 may also be present. In that case, if you want to use Python 3, be sure to specify python3.

How to Check Python Version on Linux (e.g., Ubuntu)

  1. Open Terminal Start the terminal with the keyboard shortcut (Ctrl + Alt + T).
  2. Enter the command to check Python version
   python3 --version
  1. Check the output Example:
   Python 3.9.13

Check installation location (environment variables and PATH)

After checking the version, verify the installation location if necessary. This lets you switch versions correctly even in environments with multiple Python versions.

Commands to check Python’s installation location

  • Windows:
  where python
  • macOS/Linux:
  which python3

Important notes

  • If the version isn’t displayed correctly There may be an issue with your environment variables or PATH settings. In this case, check your PATH configuration and adjust it so the correct Python binary is referenced.
  • If multiple versions are installed If multiple Python versions coexist in the same environment, the intended version may not be used. In this case, we recommend using a virtual environment (see details below).

3. Python Downgrade Steps (by OS)

Choosing the right steps to downgrade Python based on your needs

The steps to downgrade Python vary depending on your OS. Below we provide detailed downgrade instructions for Windows, macOS, and Linux. We clearly explain procedures using the official website installer and tools such as pyenv.

3.1 For Windows

Step 1: Download the installer for the older version

  1. Visit the official website Python official downloads page to access it.
  2. Find the version you want Click “View the full list of downloads” at the bottom of the page, then select the required version from the list of past releases.
  3. Download the appropriate installer
  • Choose the “Executable Installer” for Windows.
  • Check whether you need the 64bit or 32bit version and download the appropriate installer.

Step 2: Install

  1. Uninstall existing Python (if necessary)
  • Uninstall the existing Python from Control Panel > “Uninstall a program”.
  1. Install the new version Run the downloaded installer and check “Add Python to PATH” before proceeding with the installation.

Step 3: Check environment variables

  1. Ensure environment variables are correct
  • Press “Windows key + R” → type “sysdm.cpl” → open the “Environment Variables” tab.
  • Confirm that the Python installation path is included in PATH.
  1. Verify the Python version
   python --version

3.2 For macOS

Step 1: Install pyenv

  1. Verify Homebrew macOS uses Homebrew. In Terminal, enter the following to check whether Homebrew is installed.
   brew --version
If it’s not installed, follow the instructions on the official site to install it.
  1. Install pyenv Run the following in Terminal:
   brew install pyenv

Step 2: Install a Python version

  1. Check which versions are available to install
   pyenv install --list
Confirm the required version, then install it with the following command:
   pyenv install 3.9.7
  1. Switch the global version
   pyenv global 3.9.7
  1. Check the version
   python --version

3.3 For Linux (Ubuntu)

Step 1: Use update-alternatives

  1. Check which Python versions are installed
   python3 --version
  1. Add the new version Install a specific version using the following command:
   sudo apt install python3.x
  1. Switch the default version
   sudo update-alternatives --config python3
Choose the version you want to use from the displayed list.

Step 2: Use a PPA (if necessary)

If a specific version isn’t available in the repositories, add a PPA (Personal Package Archive).
  1. Add the PPA
   sudo add-apt-repository ppa:deadsnakes/ppa
  1. Install the version
   sudo apt update
   sudo apt install python3.9

Notes

  • Make version management clear When installing multiple versions, we recommend using pyenv or virtual environments so each project can use a different version.
  • Be mindful of dependencies Check in advance, as other applications running on the system may be affected.

4. Managing Python Versions with Virtual Environments

Why Use Virtual Environments

Using virtual environments lets you manage different Python versions and libraries per project without affecting the system-wide Python version. This helps resolve compatibility issues across multiple projects and minimizes the need to downgrade.

Basic Tools for Virtual Environments

venv

  • A virtual environment management tool included with Python Available in Python 3.3 and later.
  • Suitable for creating simple, lightweight virtual environments.

virtualenv

  • A virtual environment management tool provided as an external package More feature-rich than venv and compatible with Python 2.x.
  • Useful if you need flexible configuration and management of virtual environments.

pyenv-virtualenv

  • An extension that adds virtual environment functionality to pyenv Allows integrated management of multiple Python versions and virtual environments.

Creating and Using Virtual Environments

Using venv

  1. Creating a virtual environment In the terminal or command prompt, run the following command:
   python3 -m venv myenv
  • myenv is the name of the virtual environment. You can change it to any name you like.
  1. Activate the virtual environment
  • Windows: myenvScriptsctivate
  • macOS/Linux: source myenv/bin/activate
  1. Verify the virtual environment When the virtual environment is activated, the environment name (e.g., (myenv)) will appear in the prompt.
   (myenv) $
  1. Deactivate the virtual environment
   deactivate

Using virtualenv

  1. Install virtualenv
   pip install virtualenv
  1. Create a virtual environment
   virtualenv myenv
  1. Activate/Deactivate the virtual environment You can perform the same steps as with venv.

Using pyenv-virtualenv

  1. Install pyenv-virtualenv
   brew install pyenv-virtualenv
  1. Create a virtual environment
   pyenv virtualenv 3.9.7 myenv
  1. Activate the virtual environment
   pyenv activate myenv
  1. Deactivate the virtual environment
   pyenv deactivate

Use Cases for Virtual Environments

  • Use different Python versions for each project Using virtual environments allows you to run one project with Python 3.9 and another with Python 3.11.
  • Pinning library versions By creating requirements.txt, you can record the versions of libraries installed in the virtual environment and ensure reproducibility.
  pip freeze > requirements.txt
  • Isolate test environments By separating development and production environments with virtual environments, you can minimize mistakes during testing and deployment.

Notes

  • Clearly naming and locating your virtual environments helps prevent confusion when managing multiple environments.
  • Even when using virtual environments, some tools that depend on the system Python (for example, OS-specific package managers) may still be affected.
侍エンジニア塾

5. Notes and Troubleshooting

Precautions when downgrading

When downgrading Python, there are several things you should be aware of. If you don’t follow the correct procedures, you could cause unexpected issues in your system or projects.

5.1 Dependency issues

  • Assess the impact Make sure libraries and tools that depend on the Python version you’re downgrading will still work correctly. Pay special attention to the following:
  • Libraries used in your current projects that only support newer Python versions.
  • Compatibility of packages installed using pip.
  • Solutions
  • Reinstall all libraries after downgrading: pip install -r requirements.txt

5.2 Environment variables and PATH issues

  • Symptoms After downgrading, the python command may not point to the correct version. This is usually caused by problems with environment variables or PATH settings.
  • How to check
  • Windows: where python
  • macOS/Linux: which python3
  • Solution You can fix the problem by correcting your PATH settings. The following steps show how to do this on Windows:
  1. Open “System Properties” > “Environment Variables”.
  2. Edit the PATH variable and make sure it includes the installation directory of the downgraded Python.
  3. Remove any unnecessary entries (old paths).

5.3 Version switching not taking effect

  • Symptoms The version shown in the terminal is different from the intended one.
  • Solution
  • If you’re using pyenv, run the following command to set the version explicitly: pyenv rehash To set it system-wide, use the pyenv global command.

Troubleshooting Examples

Error Example 1: “Python not found” is displayed

  • Cause The Python installation path is not set in the environment variables, or it is incorrect.
  • Solution Check the installation path and add the correct path to the environment variables.

Error Example 2: Cannot import a library

  • Cause A downgrade may have left the library uninstalled.
  • Solution Reinstall the required libraries:
  pip install library name

Error Example 3: “No module named ‘pip'” is displayed

  • Cause pip is not installed or is corrupted.
  • Solution Reinstall pip:
  python -m ensurepip
  python -m pip install --upgrade pip

Post-downgrade Checklist

  • Check Python version Run the following in the terminal to confirm it has switched to the correct version:
  python --version
  • Verify libraries are working Run the project to verify that key libraries are functioning correctly.

6. Summary

Recap of this Article

In this article, we explained in detail the following points about the specific steps for downgrading Python versions:
  1. How to check the Python version We explained how to check the current Python version on each OS (Windows, macOS, Linux).
  2. Downgrade steps by OS We explained in detail using the official installer on Windows, using pyenv on macOS, and installation methods using update-alternatives and PPAs on Linux.
  3. Using virtual environments We introduced how to use venv, virtualenv, and pyenv-virtualenv to manage different Python versions and libraries per project.
  4. Precautions and troubleshooting We discussed common issues and error causes that can occur during downgrades, and provided concrete examples of solutions.

The Importance of Proper Python Version Management

Managing Python versions greatly affects development efficiency and stability. Because downgrading is often only a temporary fix, adopting the following approaches can make long-term management easier:
  • Use virtual environments By creating isolated environments for each project, you can manage versions and libraries flexibly without affecting the entire system.
  • Use pyenv Using a tool that efficiently manages multiple Python versions can minimize the effort required for downgrades and upgrades.

Next steps

  • Downgrade Python by following the steps Use the methods described in this article as a guide to switch versions properly.
  • Try virtual environments Using virtual environments lets you manage projects more efficiently. We recommend setting up a virtual environment first when starting a new project.

Message to Readers

Managing Python versions is an unavoidable challenge for everyone from beginners to advanced users. I hope this article helps you set up your development environment and keeps your projects running smoothly. If you have any questions or issues about version management, including downgrading, please feel free to ask!
RUNTEQ(ランテック)|超実戦型エンジニア育成スクール