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.
$ brew unlink python
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
$ brew switch python 3.6.5
$ pip install tensorflow
If you are working with Anaconda, then
conda install python=3.5.0
# or maybe
conda install python=2.7.8
# or whatever you want....
might work.
Here is a canonical summary which sums up different solutions for the variety of operating system Python runs on. What follows are possibilities for Microsoft Windows, Linux, macOS and Misc.
As mentioned those are just possibilities - by no means do I claim to have a complete list whatsoever.
In general, it's suggested to use virtual environments (I highly suggest looking at the official Python documentation). With this approach, you easily can set up project-specific Python versions (as well as libraries). Easily manageable and the best part: There are lots of tutorials on the internet on how to approach this:
1.) Open command prompt ("cmd") and enter pip install virtualenv
.
2.) Install your desired Python version via https://www.python.org/downloads/release; Remember: Do not add to PATH
!
3.) Type into the command prompt: virtualenv \path\to\env -p \path\to\python_install.exe
, whereas \path\to\env
shall be the path where your virtual environment is going to be and \path\to\python_install.exe
the one where your freshly (presumably) installed Python version resides.
4.) Done! You now have a virtual environment set up! Now, to activate the virtual environment execute the batch file which is located inside the \path\to\env\Scripts\activate.bat
. (cf. this website or an official Python guide)
The basic option would be to uninstall the unwanted Python version and re-install the favored one from https://www.python.org/downloads/. To remove the "old" version go to Control Panel
-> "Uninstall a program"
-> Search for "Python"
-> Right-click on the Python name
-> Uninstall
. Bear in mind that Python usually has a PATH variable stored, hence you should remove it as well - Check the following links for this:
Now double-check whether there are any remaining files where Python used to be stored. Usually, you can find all the Python files at either C:\Program Files (x86)\Pythonxx
, C:\Users\username\AppData\Local\Programs\Pythonxx
or C:\Pythonxx
or all of them. You might have installed it in another directory - check where it once was.
Now after de-installing just re-install the wanted version by going to the download page and follow the usual installation process. I won't go into details on how to install Python.. Lastly, you might check which version is currently installed by opening the command prompt and typing python -V
.
This approach is pretty similar to the second one - you basically uninstall the old one and replace it by your favored version. The only thing that changes it the part regarding how to uninstall the unwanted Python distribution: Simply execute the Python3 installer you originally used to install Python (it's usually stored in your Python directory as mentioned above; for more assistance check out this). There you get an option to repair or uninstall
, proceed by choosing uninstall
, and follow the steps provided via the uninstaller.
No matter how you uninstall Python (there are many resources on this topic, for example this Stack Overflow question or a problem thread a user by the name of Vincent Tang posted on the Stack Exchange site Super User, etc.), just reinstall the wanted Python version by following the steps mentioned in Option 2
.
Option 4 deals with Anaconda. Please refer to this site on how to install Anaconda on Windows. Step 9
is important as you don't want to install it as your default Python - you want to run multiple versions of Python:
Choose whether to register Anaconda as your default Python. Unless you plan on installing and running multiple versions of Anaconda or multiple versions of Python, accept the default and leave this box checked.
Follow the official tutorial I linked above.
Once done you can create the following commands individually in the anaconda prompt: To overwrite the default python version system-wise use conda install python=3.6
or to create a virtual environment go ahead and use conda create -n $PYTHON36_ENV_NAME python=3.6 anaconda
whereas $PYTHON36_ENV_NAME
is the custom name you can set. Credit where credit is due - the user @CermakM from this thread strongly influenced this snippet.
In my research I encountered a bunch of useful Stack Overflow threads - you might check them out if you go the tough road with Anaconda:
What follows isn't a downgrade in the classical sense - though for the sake of completeness I decided to mention this approach as well. On Windows you're also able to run multiple Python versions - an infamous thread on StackOverflow deals with this question, thus I politely refer you to there for further reading purposes.
Pretty analog to the third option for Windows I highly suggest you use a virtual environment such as Anaconda. Anaconda - or short conda - is also available on Linux. Check the official installation documentation here. Once again this thread is highly suggested on how to overwrite a Python version, respectively how to specifically create an environment with your wanted Python version.
Another highly suggested virtual environment is Pyenv
. The user @Sawan Vaidya described in this Stack Overflow question on how to up-or downgrade a Python version with the help of Pyenv
. You can either set a Python version globally or create a local environment - both explained in the mentioned thread.
Another user, namely @Jeereddy, has suggested to use the software package management system Homebrew
. He explained this option thoroughly in this current question:
$ brew unlink python
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
$ brew switch python 3.6.5
No need to reinvent the wheel - this thread is filled with lots of beautiful running approaches such as the one by @Sidharth Taneja.
normal package
.cd /Library/Frameworks/Python.framework/Version
ls
to list all installed Python versionssudo rm -rf 3.7
, removing Python version 3.7 - can be repeated for whatever version(s) you want to deletepython3 -v
, it should display the version you originally wanted to have installedWhat a goldmine this thread is! As @nondetermistic has described in-depth (direct link to his post):
Install Python source code as it is like this:
#Taken Python 3.6 as an example
$ mkdir /home/<user>/python3.6
$ ./configure --prefix=/home/<user>/python3.6/
$ make altinstall
You're now able to either add the downloaded version (/home/<user>/python3.6/bin
) to PATH
as well as lib
to LD_LIBRARY_PATH
or just create a virtual environment by: /home/<user>/python3.6/bin/python3.6 -m venv env-python3.6
. A very aesthetic and simple solution to run multiple Python versions on your system.
Using pyenv
with Homebrew
- credit to @Shayan with his reply here:
1.) Installing pyenv
with Homebrew
:
brew update
brew install pyenv
2.) Cloning the GitHub repository to get latest pyenv
version:
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
3.) Defining the environment variables as follows
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
4.) Restarting shell so PATH
change works
exec "$SHELL"
5.) Checking the available Python versions
pyenv install --list
6.) Installing the wanted Python version, e.g. 3.6
pyenv install 3.6
7.) Setting it globally (you can also go ahead and only use it in a certain environment)
pyenv global 3.6
8.) Check the Python version the system is using - your wanted / downgraded version should be displayed here.
python3 --version
Similar to previous approaches you can download Anaconda on macOS as well. For an installation guide click here. The usage is pretty much the same as I've already described in Option 4
of the Windows
guide. Please check out above.
In this case it's getting pretty repetitive. I kindly suggest you to check the following resources for further reading:
When writing this post I had the problem of not knowing where to draw the line. When looking up the operating systems Python currently supports you get a huge list, including the ones I mentioned, i.e. Linux, Microsoft Windows and macOS, though obviously different Linux distributions are single-handedly treated, e.g. CentOS, Arch Linux or Fedora should deserve a spot as well - or shall I make separate options for Windows 10, 7, etc.?
Due to the high degree of repetitiveness as far as modules like Homebrew, Conda or alike are concerned I decided to limit my list to the "main three" operating systems - distributions like Ubuntu (How do I downgrade my version of python from 3.7.5 to 3.6.5 on ubuntu), CentOS (How to downgrade python version on CentOS?) can be easily researched on Stack Overflow. Most often than not you can apply solutions from the Linux tab for said distributions. The same goes with Windows and macOS (versions).
create a virtual environment, install then switch to python 3.6.5
$ conda create -n tensorflow python=3.7
$ conda activate tensorflow
$ conda install python=3.6.5
$ pip install tensorflow
activate the environment when you would want to use tensorflow
Download python 3.6.0 from https://www.python.org/downloads/release/python-360/
Install it as a normal package.
Run cd /Library/Frameworks/Python.framework/Version
Run ls
command and all installed Python versions will be visible here.
Run sudo rm -rf 3.7
Check the version now by python3 -V
and it will be 3.6 now.
Create a python virtual environment using conda, and then install the tensorflow:
$ conda create -n [environment-name] python=3.6
# it may ask for installing python-3.6 if you don't have it already. Type "y" to proceed...
$ activate [environment-name]
$ pip install tensorflow
From now on, you can activate the environment whenever you want to use tensorflow.
If you don't have the conda package manager, first download it from here: https://www.anaconda.com/distribution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With