3

I would like to ask if it is possible to make Python 3 a default interpreter on Mac OS 10 when typing python right away from the terminal? If so, can somebody help how to do it? I'm avoiding switching between the environments.

Cheers

Andile
  • 384
  • 2
  • 3
  • 12

2 Answers2

8

Method 1:

In ~/.bash_profile, set an alias for your python3

alias python='python3'

Method 2(I use this way to keep multiple python versions):

Install python3(the virtualenv python3 on my machine is env-3.5) by virtualenv, in ~/.bash_profile activate certain virtual environment:

source /Users/username/.virtualenvs/env-3.5/bin/activate

I suggest use a virtual environment, it will affect your system even packages messed up.

update:

Did research on anaconda which data_garden commented. Here I post how I installed it:

  • Go to page https://www.anaconda.com/download/#macos find the package meet your system requirement, for me it's MacOS
  • Add to system PATH export PATH=$HOME/anaconda3/bin:$PATH into .bash_profile
  • Search available python versions conda search "^python$"
  • Create env: conda create -n env-3.6.5 python=3.6.5 , env-3.6.5 is the name of the new created env
  • Activate env: source activate env-3.6.5, add it into .bash_profile

Done!

You can run conda env list to display all virtual environments you have created.

enter image description here

Community
  • 1
  • 1
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
1

You can do that by changing alias, typing in something like $ alias python=python3 in the terminal. If you want the change to persist open ~/.bash_profile using nano and then add alias python=python3. CTRL+O to save and CTRL+X to close. Then type $ source ~./bash_profile in the terminal.

Richie Bendall
  • 7,738
  • 4
  • 38
  • 58
unholy_me
  • 460
  • 3
  • 14