Install both Python 2 and 3 on your mac

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 python3
brew install python
# Going to upgrade
brew upgrade python

Step 2: Install Python2

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

# Going to install python2
brew install python@2

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

# python and python2 are now referring to Python 2.7.15
~ python
Python 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 darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
~ python2
Python 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 darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
# python3
~ python3
Python 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 darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

One More Thing: Use `virtualenv`

# To use virualenv for python2
virtualenv -p python2 env_name
# Then in the install
pip2 install lib_name
#To use virualenv for python3
virtualenv -p python3 env_name
# Then in the install
pip3 install lib_name

Reference

https://needone.app/?p=1082

About: arkilis


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.