Downgrade Python Version

Downgrade Python Version

  1. Downgrade Python Version on Windows
  2. Downgrade Python Version on Linux
  3. Downgrade Python Version on macOS

Python is maintained and updated regularly. Some new features are added on every update, and some old ones may get deprecated.

Some updates are major, while others might include minor changes. The code written in a specific Python version may or may not be compatible with other versions (the main example being the difference between Python 2 and Python 3).

This tutorial will demonstrate how to downgrade Python according to our needs on different devices. We will discuss methods for Windows, Linux, and Mac devices.

Downgrade Python Version on Windows

Reinstall to Downgrade Python on Windows

The first few methods involve uninstalling the current version of Python and installing the required version. There are several ways to achieve this.

The first method involves uninstalling the current Python version from the Control Panel. We can search for the Add or Remove Programs application in the Control Panel.

This application contains a list of all the programs installed on the device. We can select the installed version of Python from this list, right-click to select the uninstall option, and follow the steps.

Another way to uninstall the installed version of Python is by using the Python package installer used earlier to install Python. We get the repair and uninstall options on running the Python package installer.

We can click on the uninstall option and proceed with the required steps.

After using any of the previous methods, it is necessary to delete the Python files available in the directory of the same name (usually found in the C:\Program Files directory). It is also necessary to make sure that the path from the environment variable is removed.

After carrying out the uninstallation of Python, we can install the required version and download its package installer application from the official website of Python.

Use a Virtual Environment to Downgrade Python on Windows

Python allows us to create different virtual environments. Each virtual environment can have its required version of Python interpreter and packages.

To create a virtual environment, we can use the command pip install virtualenv on the command prompt. We need to download the required version from the official website.

After this, we need to execute virtualenv \pathof\the\env -p \pathof\the\python_install.exe. The former path is the path where we wish to store the environment, and the latter is the path where the installer is present.

Use Anaconda Prompt to Downgrade Python on Windows

This method is limited to the users of Anaconda Navigator. On the Anaconda prompt, we can install the required version of Python and overwrite the previous version using the conda install python= version command.

It is necessary to check if this version is available or not by running the conda search python command and checking for the available versions.

We can also create a new environment very easily in Anaconda. We can run the conda create --name env_name python=python_version command to create an environment.

Downgrade Python Version on Linux

Reinstall to Downgrade Python on Linux

We can remove and install the required version of Python to downgrade it. First, we need to download the package from the official website and install it.

Then, we need to go to the Frameworks\Python.framework\Versions directory and remove the version which is not needed. We will run the sudo rm -rf python_version command in this directory to remove this version.

Use Pyenv to Downgrade Python on Linux

Pyenv allows us to switch between different versions of Python by creating environments.

We can install the required version of Python using the pyenv install python_version command on the terminal. After that, we can view the available versions using the pyenv versions command.

To set the required version as the Python version for the local environment, we can use the pyenv local python_version command.

Next, we can switch to a different folder and set the required Python version globally. To set the version globally for a user, we use the pyenv global python_version command.

Use Homebrew to Downgrade Python on Linux

Homebrew is an application manager that can manage and install open-source applications. It is available on macOS and Linux.

We can clone to the repository of our required version of Python and unlink the previous version using a set of simple commands. These are shown below.

brew unlink python
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
brew switch python python_version

Use Anaconda to downgrade Python on Linux

Anaconda is also available on macOS and Linux devices. We can follow the steps discussed in the previous section of Downgrade Python on Windows and use them for these devices.

Downgrade Python Version on macOS

On macOS, we can use the methods involving Pyenv, Homebrew, and Anaconda discussed in the previous section. These methods are valid here as well.

Author: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.

LinkedIn

Related Article - Python Version

  • Check the Python Version in the Scripts
  • Switch Between Python 2 and 3
  • Use Pip to Install Python Version
  • Specify Virtual Environment for a Python Version
  • Downgrade Python 3.9 to 3.8