Switch python version in osx

I have python 3.7 installed but will need to run something with python 3.6. Here are the steps to do so.

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

To switch it back to python 3.7

brew switch python 3.7.0

Now with two versions installed, we can use virtualenv for projects.

Notice that when you issue virtualenv –python=$(which python3) env, virtualenv may throw an error -bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory. That’s because the virtualenv script has a shebang line referencing python 3.7. To fix that error, edit that file /usr/local/bin/virtualenv and change the version to 3.6. Then virtualenv will work fine.

Ref:
https://stackoverflow.com/questions/51726203/installing-python3-6-alongside-python3-7-on-mac
https://stackoverflow.com/questions/45269867/python-virtualenvwrapper-bad-interpreter/48259762#48259762

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s