Python is an extremely popular programming language used for a wide variety of applications. As new versions of Python are released, they introduce useful features and improvements. However, sometimes, you may need to downgrade to an older Python version for compatibility reasons.
Downgrading from Python 3.7 to 3.6 can be tricky but is entirely doable with the right approach. This comprehensive guide will cover several methods to downgrade Python on Windows, Linux, and Mac operating systems.
Downgrading Python from version 3.7 to 3.6 involves a few critical steps. For Windows, you can either install an older Python version alongside the existing one or use the pyenv version manager. MacOS users can choose between pyenv and virtualenv, while Linux offers options like installing from source, pyenv, or virtualenv. Each method has its pros and cons, but ultimately allows for effective version management and environment isolation
Why Downgrade Python?
There are a few key reasons why you may need to downgrade from Python 3.7 to 3.6:
- You rely on a library or framework that is not yet compatible with Python 3.7
- You need to replicate a production environment locally that runs on Python 3.6
- You are working with legacy codebases that require Python 3.6 to function properly
- You want to leverage specific features only present in Python 3.6
For any of these reasons, switching between Python versions is very useful.
Also read: Activating a Virtual Environment in Windows 10 Command Prompt
Setting Up for Python Downgrade
Before downgrading, it is highly recommended to create a virtual environment. Virtual environments allow you to encapsulate Python versions and package installations so they do not interfere with other projects.
Here is how to set up a virtual environment:
python3 -m venv my_venv
source my_venv/bin/activate
This will create an isolated Python environment called my_venv
. We can now install packages here without affecting the system Python installation.
Let’s first check our starting Python version:
python --version
# Python 3.7.4
We are currently on Python 3.7.4. Our goal is to downgrade to 3.6.
Also read: 3 Approaches to Removing the Duplicate Words From a Text
Steps for Downgrading Python in Windows
There are a couple of good options for downgrading Python on Windows:
1. Install an Older Python Version
The simplest method is to install an older Python version separately alongside the existing installation.
- Download the Python 3.6 installer for Windows from python.org.
- Run the installer, being sure to check “Add Python to PATH”:
- Open a new terminal window and verify Python downgraded to 3.6:
python --version
# Python 3.6.8
We now have Python 3.6.8 available, isolated from the system Python 3.7. To switch back, close the terminal and reopen or run:
path %PATH%;
python --version # Python 3.7 again
2. Use pyenv Version Manager
pyenv is a useful tool for managing multiple Python versions.
To install on Windows:
# Install pyenv using pip
pip install pyenv-win
# Set environment variables
pyenv init
# reload shell
Now we can install Python 3.6:
pyenv install 3.6.8
pyenv global 3.6.8
Check Python downgraded:
python --version
# Python 3.6.8
When done working with 3.6, switch versions with:
pyenv global 3.7.4
Comparing Python Downgrade Techniques on Windows
Method | Pros | Cons |
---|---|---|
pyenv | Easily switch versions | Slower install |
Virtualenv | Uses system Python | Need full path |
Downgrading Python on MacOS
The two best options for downgrading Python on Mac are pyenv and virtualenv.
1. pyenv Method
As covered above, pyenv is a great version manager for MacOS.
Installation is simple using Homebrew:
brew update
brew install pyenv
Now install Python 3.6:
pyenv install 3.6.8
pyenv global 3.6.8
python --version
# Python 3.6.8
2. Virtualenv Method
Virtualenv is included by default with Python installs.
Create a Python 3.6 virtualenv:
virtualenv -p /usr/bin/python3.6 my_venv
source my_venv/bin/activate
python --version
# Python 3.6.8
This isolates Python 3.6 without needing to change global versions.
Deactivate when done:
deactivate
Comparison of Mac Python Downgrade Methods
Method | Pros | Cons |
---|---|---|
pyenv | Easily switch versions | Slower install |
Virtualenv | Uses system Python | Need full path |
Downgrading Python on Linux
Linux offers the most flexibility in downgrading Python versions. Here are some great options.
1. Install Older Python
Downloading and manually installing an older Python version is straightforward:
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
tar xzf Python-3.6.8.tgz
cd Python-3.6.8
./configure --enable-optimizations
make -j 8
sudo make altinstall
This compiles Python 3.6.8 from source and installs it separately from the system Python.
Now verify Python 3.6.8 is active:
python --version
# Python 3.6.8
2. Use pyenv
Our friend pyenv also works great on Linux!
Install pyenv and setup environment variables:
# Install pyenv
curl https://pyenv.run | bash
# Add pyenv init to shell config
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
# Reload shell
exec "$SHELL"
Now install Python 3.6.8:
pyenv install 3.6.8
pyenv global 3.6.8
python --version
# Python 3.6.8
When finished, change versions:
pyenv global 3.7
3. Use Virtualenv
As on other platforms, Python virtual environments are an excellent way to manage Python versions on Linux.
Create a virtual environment called my_venv
with Python 3.6:
python3.6 -m venv my_venv
source my_venv/bin/activate
python --version
# Python 3.6.8
Python is now isolated in my_venv
without any system changes.
Deactivate the environment when finished:
deactivate
Comparison of Linux Python Downgrade Methods
Method | Pros | Cons |
---|---|---|
Install from Source | Simple, no dependencies | Manual process |
pyenv | Powerful version manager | Complex setup |
Virtualenv | Uses system Python | Env management |
Summary and Next Steps
We covered several effective methods to downgrade from Python 3.7 to 3.6 across Windows, MacOS, and Linux platforms. The choice depends on your needs:
- Install older version – Quick and standalone
- pyenv – Feature-rich version manager
- Virtualenv – Environment isolation
Downgrading Python can enable legacy application support, utilize vital libraries, and unlock access to key features of 3.6. With this guide, you should feel empowered to smoothly downgrade and switch between Python versions for your projects. As next steps, consider exploring Python virtualization using Docker containers if additional flexibility is needed in replicated production environments.