Since Tensorflow is not yet available via pip for Python 3.7 and pyenv can't build python on the latest macOS, let's install 3.6.5_1
via homebrew and use it in conjunction with pyenv to create an enclosed environment that will use 3.6 only when we need it:
brew unlink python
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
brew switch python 3.7.2_1
Install pyenv if you haven't already, we'll use it to switch to 3.6.5
only when we need it (e.g. jupyter), leaving the latest Python from homebrew as default release (e.g. 3.7.2_1
):
brew install pyenv
pyenv rehash
And then add eval "$(pyenv init -)"
to your .bash_profile
Add links to homebrew's pythons to pyenv:
ln -s /usr/local/Cellar/python3/3.6.5_1 ~/.pyenv/versions/3.6.5_1
ln -s /usr/local/Cellar/python3/3.7.2_1 ~/.pyenv/versions/3.7.2_1
And now fix the symbolic links to all the python 3.6 binaries (homebrew doesn't create them since 3.6 is not the currently selected version, we need to do it manually):
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/2to3-3.6 /usr/local/opt/python/bin/2to3-3.6
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/idle3.6 /usr/local/opt/python/bin/idle3.6
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/pydoc3.6 /usr/local/opt/python/bin/pydoc3.6
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/local/opt/python/bin/python3.6
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config /usr/local/opt/python/bin/python3.6-config
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6m /usr/local/opt/python/bin/python3.6m
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config /usr/local/opt/python/bin/python3.6m-config
ln -s /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework/Versions/3.6/bin/pyvenv-3.6 /usr/local/opt/python/bin/pyvenv-3.6
Now you are all set. Let's suppose you plan to run a jupyter notebook/lab using tensorflow, the first thing you need to do is set a local python release, running from the directory containing the notebooks (more practical this way):
pyenv local 3.6.5_1
Then just install the packages you need with pip3 and launch jupyter from this directory and it will be executed using python 3.6.5.