Homebrew: Rollback from Python 3.7 to Python 3.6.5.x?

If you still have the previous versions available, you can just use

brew switch python 3.6.5_1

If you don't have previous version to switch to, you can install Python 3.6.5_1 from previous formula this way:

$ brew unlink python

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

If you are getting:

# --ignore-depeError: python contains a recursive dependency on itself:
  python depends on sphinx-doc
  sphinx-doc depends on python

...then run:

$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

...instead of the last command.

If then you will get the following error when you do pip3 install after such installation:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

...then a workaround may be to install its dependencies first (everything except sphinx-doc)

$ brew install pkg-config gdbm openssl readline sqlite xz

Notice that it needs openssl and NOT [email protected] which is a latest dependency in homebrew python 3.7.*.


Two options

To recover a previously installed Python version:

brew switch python 3.x.x_x # Ex. 3.6.5_1

Use brew info python to see what you have previously installed

To make a clean install of Python 3.6.5 use:

brew unlink python # If you have installed (with brew) another version of python
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

Long Answer

There are two formulas for installing Python with Homebrew: python@2 and python.
The first is for Python 2 and the second for Python 3.

Note: You can find outdated answers on the web where it is mentioned python3 as the formula name for installing Python version 3. Now it's just python!

By default, with these formulas you can install the latest version of the corresponding major version of Python. So, you cannot directly install a minor version like 3.6.

Solution:

With brew, you can install a package using the address of the formula, for example in a git repository.

brew install https://the/address/to/the/formula/FORMULA_NAME.rb

Or specifically for Python 3

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/COMMIT_IDENTIFIER/Formula/python.rb

The address you must specify is the address to the last commit of the formula (python.rb) for the desired version. You can find the commint identifier by looking at the history for homebrew-core/Formula/python.rb

https://github.com/Homebrew/homebrew-core/commits/master/Formula/python.rb

Python > 3.6.5

In the link above you will not find a formula for a version of Python above 3.6.5. After the maintainers of that (official) repository released Python 3.7, they only submit updates to the recipe of Python 3.7.

As explained above, with homebrew you have only Python 2 (python@2) and Python 3 (python), there is no explicit formula for Python 3.6.

Although those minor updates are mostly irrelevant in most cases and for most users, I will search if someone has done an explicit formula for 3.6.