Make Python 3 default on Mac OS?

12,868

Solution 1

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

Solution 2

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.

Share:
12,868
Andile
Author by

Andile

Updated on June 30, 2022

Comments

  • Andile
    Andile almost 2 years

    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