How to Downgrade Python Version on Windows, Linux, and MacOS

While working with Python, it’s not uncommon for developers to need different versions for different projects. In this article, we will explore the process of downgrading Python from version 3.10 to 3.9 on various operating systems including Windows, Linux, and Mac operating systems. We will also discuss common problems and their solutions that may arise during the downgrade process.

For compatibility and functionality, it is crucial to have an appropriate Python version installed. If you find that your current Python version is causing issues or is not compatible with specific libraries, downgrading to a previous version might be the last solution.

 

Downgrading Python on Windows

Following are the ways to downgrade Pythong on the Windows operating system:

Uninstall the current Python version

 

  1. First, open the Control Panel.
  2. Find and click on “Uninstall a program” under “Programs.”
  3. Find your current Python installation (Python 3.10) and click “Uninstall.”
  4. Then complete the uninstallation process by following the steps.

 

Install desired Python version

  1. Go to the Python Releases for Windows page.
  2. Download the Python 3.9 installer for your Windows version (32-bit or 64-bit).
  3. Run the installer and follow the on-screen instructions to complete the installation process.

 

Downgrading Python on Linux

 

Using update-alternatives

 

  1. Open the terminal.
  2. Check the available Python versions using the following command:
sudo update-alternatives --list python
  1. If Python 3.9 is listed, you can set it as the default version using the following command:
sudo update-alternatives --set python /usr/bin/python3.9

If Python 3.9 is not listed, proceed to the next method.

 

Using pyenv

 

  1. Install pyenv using the following command:
curl https://pyenv.run \| bash
  1. Add the following lines to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc):
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Restart your terminal or run source ~/.bashrc (or source ~/.zshrc).
  2. Install Python 3.9 using the following command:
pyenv install 3.9.0
  1. Set Python 3.9 as the global default version using the following command:
pyenv global 3.9.0

 

Downgrading Python on macOS

 

Using brew

 

  1. Install Homebrew if you haven’t already by following the instructions on brew.sh.
  2. Install Python 3.9 using the following command:
brew install [email protected]
  1. Add the following line to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile):
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
  1. Restart your terminal or run source ~/.bashrc (or source ~/.zshrc or source ~/.bash_profile).

 

Using pyenv

 

  1. Install pyenv using Homebrew with the following command:
brew install pyenv
  1. Add the following lines to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile):
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Restart your terminal or run source ~/.bashrc (or source ~/.zshrc or source ~/.bash_profile).
  2. Install Python 3.9 using the following command:
pyenv install 3.9.0
  1. Set Python 3.9 as the global default version using the following command:
pyenv global 3.9.0

 

Common Problems and Solutions

Here are some common problems you may face while downgrading the Python version with their possible solutions:

ImportError: No module named ‘xyz’

This error occurs when the required module is not installed. To fix this, install the module using pip:

pip install xyz

 

ModuleNotFoundError: No module named ‘xyz’

Similar to the ImportError, this error occurs when the required module is not installed. Install the module using pip:

pip install xyz

 

AttributeError: ‘module’ object has no attribute ‘xyz’

This error occurs when you are trying to access an attribute or function that does not exist in the imported module. Check the module’s documentation to ensure you are using the correct attribute or function name.

 

ValueError: unknown locale: UTF-8

This error occurs when your system does not recognize the UTF-8 locale. To fix this, add the following lines to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile):

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Restart your terminal or run source ~/.bashrc (or source ~/.zshrc or source ~/.bash_profile).

 

Conclusion

You can easily downgrade Python from version 3.10 to 3.9  on Windows, Linux, and macOS by following the steps outlined in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *