Install both Python 2 and 3 on your mac

Needone App
2 min readJun 10, 2018

--

Step 1: Install Python3

Use brew install python to install python3 on the mac, current version is Python 3.6.5. If your mac has a python2 already, brew will ask for an upgrade, which is fine.

# Going to install python3brew install python# Going to upgradebrew upgrade python

Step 2: Install Python2

Homebrew does provide a python2 version, which you can install by

# Going to install python2brew install python@2

After finished the above two steps, now you can have:

# python and python2 are now referring to Python 2.7.15➜  ~ pythonPython 2.7.15 (default, Jun  9 2018, 23:00:09)[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwinType "help", "copyright", "credits" or "license" for more information.>>>➜  ~ python2Python 2.7.15 (default, Jun  9 2018, 23:00:09)[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwinType "help", "copyright", "credits" or "license" for more information.>>># python3➜  ~ python3Python 3.6.5 (default, Jun  9 2018, 22:53:53)[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwinType "help", "copyright", "credits" or "license" for more information.>>>

One More Thing: Use `virtualenv

# To use virualenv for python2virtualenv -p python2 env_name# Then in the installpip2 install lib_name#To use virualenv for python3virtualenv -p python3 env_name# Then in the installpip3 install lib_name

Reference

--

--