Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to install Python3 using brew

Trying to install Python3 in mac using below command :

brew install python3

When i run the command getting below error :

Error: python 2.7.14_2 is already installed
To upgrade to 3.6.5, run `brew upgrade python`

How to keep both python2 and python3 in mac without upgrading...

Thanks!

like image 632
sainadh Avatar asked Apr 05 '18 12:04

sainadh


1 Answers

The python formula is assumed by Homebrew to be Python 3. The formula python3 is thus an alias for python.

You need to:

  1. brew upgrade python, as told by the error message. It will switch your default Homebrew Python from 2 to 3.
  2. brew install python@2. It will install Python 2 alongside Python 3.

Note however that even with Python 3 installed (using the formula called python), the command python still points to Python 2. You need to either type python3 to run Python 3, or add Homebrew’s Python 3 unprefixed bin directory at the beginning of your $PATH:

export PATH="$(brew --prefix python)/libexec/bin:$PATH"
like image 103
bfontaine Avatar answered Nov 11 '22 17:11

bfontaine