Downgrading Python to version 3.6.5_1 with Homebrew on Mac OS X

After running brew update; brew upgrade, brew updated python to version 3.7.x.x. When my code stopped working, I noticed that some of the 3rd party packages i use are not compatible Python 3.7.x.x yet. So i decided to revert to Python 3.6.5_1 the version that i am certain i will not have any troubles with.

I failed after trying to to revert to an older version using the usual method: brew install python@3.6.5_1 or: brew install python@3.6.5 or even: brew install python@3.6

After spending some time testing solutions i found the following posts that explained the situation to a great extent:

So, without further due, here is the solution:

First let’s ask brew to remove the links to the most recent python version, that brew installed automatically:

$ brew unlink python

Then let’s install the version 3.6.5_1 by directing brew to the suitable commit of the python brew formula on the Homebrew formulae repository. The commit ID for Python 3.6.5_1 Formula is: f2a764ef944b1080be64bd88dca9a1d80130c558. To avoid the issue with circular dependencies the flag –ignore-dependencies must be used:

$ brew install --ignore-dependencies

Then let’s ask brew to create the links to the freshly installed version of python:

$ brew switch python 3.6.5_1

Now could create a python 3.6.5_1 virtual environment to use it in a specific project, and then let brew update your python installation. To achieve that result with the module venv use the --copies option to make sure copies of the binaries (python, pip, etc.) were copied to the virtual environment folder. If --copies was not specified, venv will create symbolic links to the python binaries, and that means you will lose the correct version of python once brew upgrades the python binaries.

$ python -m venv myvenv --copies

Alternatively, you could stop brew from automatically upgrading python when running brew upgrade. You simply have to tell brew that you don’t want to upgrade the python formula in the future:

$ brew pin python

You can allow brew to upgrade python by simply reverting the previous action:

$ brew unpin python

I hope this post was useful!