[python] Updating Python on Mac

I wanted to update my python 2.6.1 to 3.x on mac but i was wondering if its possible to do it using terminal or i have to download the installer from python website?

The reason why i am asking this question is because installer is not updating my terminal python version.

This question is related to python macos python-3.x

The answer is


If it were me, I would just leave it as it is. Use python3 and pip3 to run your files since python and python3 can coexist.

brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python

You can use the above line but it might have unintended consequences.


I wanted to achieve the same today. The Mac with Snow Leopard comes with Python 2.6.1 version.

Since multiple Python versions can coexist, I downloaded Python 3.2.3 from: http://www.python.org/getit/

After installation the newer Python will be available under the Application folder and the IDE there uses 3.2.3 version of Python.

From the shell, python3 works with the newer version. That serves the purpose :)


I believe Python 3 can coexist with Python 2. Try invoking it using "python3" or "python3.1". If it fails, you might need to uninstall 2.6 before installing 3.1.


I was having the same problem, but then after a bit of research I tried

brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python

in terminal

A warning message will pop-up saying that python 3.7.0. is already installed but it's not linked so type the command brew link python and hit enter and hope things work right for you


using Homebrew just do:

brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python

done :)


You can also use:

brew upgrade python3

First, install Homebrew (The missing package manager for macOS) if you haven': Type this in your terminal

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Now you can update your Python to python 3 by this command
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python

Python 2 and python 3 can coexist so to open python 3, type python3 instead of python

That's the easiest and the best way.


Easiest way is

 brew update && brew upgrade python

Python 2.7 and 3 can co-exist.
Python version shows on terminal is 2.7, but you can invoke it using "python3", see this:

PeiwenMAC:git Peiwen$ python --version
Python 2.7.2
PeiwenMAC:git Peiwen$ python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Both python 2x and 3x can stay installed in a MAC. Mac comes with python 2x version. To check the default python version in your MAC, open the terminal and type-

python --version

However to check, if you have already installed any of python 3x versions, you need to type

python3 --version

If you don't then go ahead and install it with the installer. Go the the python's official site(https://www.python.org/downloads/), download the latest version

enter image description here

and install it.

Now restart the terminal and check again with both commands-

enter image description here

Hope this helps.


On a mac use the following in the terminal to update python if you have anaconda:

conda update python

Its always best to use homebrew to update or install python. In terminal type:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

This will install homebrew (it takes sometime depending on your internet speed)

Then, in terminal, type

brew update

This will first update brew (you don't have to do that if you already have the latest version)

then type

brew upgrade python

This brew will update python to the latest viable version.

That should do it.


This article helped me to make the right choices eventually since mac 10.14.6 by default came with python 2.7* and I had to upgrade to 3.7.*

brew install python3
brew update && brew upgrade python
alias python=/usr/local/bin/python3

Referred The right and wrong way to set Python 3 as default on a Mac article


I recommend using pyenv to manage your local python versions (both 2.x and 3.x) instead of installing new versions directly with homebrew or building new python versions from source manually. Essentially, pyenv can do two key things for you:

  • Install different python versions under some directory. Doing pyenv install 3.8.1 will install python 3.8.1 under ~/.pyenv/versions/3.8.1.
  • Modify your shell environment (PATH) with shims so that when you do pyenv local 3.8.1, calling python will invoke the new interpreter instead of your system python.

MacOSX Specific Installation

The pyenv repo is pretty detailed on how to install for different systems and what it's actually doing, but here's the basic steps for mac:

  1. Install homebrew if you don't already have it and use it to install pyenv with brew install pyenv
  2. Once you have pyenv installed, update your .bash_profile file to include:
if command -v pyenv 1>/dev/null 2>&1; then
    eval "$(pyenv init -)"
fi

Now install some python using pyenv and then switch to it with the pyenv local command (you can see all your versions with pyenv versions).

pyenv install 3.8.1 && pyenv local 3.8.1

Note: you may need to create a new shell or reload your bash_profile in your current shell for the pyenv initialization to do its thing (set up shims).

With this setup, you'll be able to keep your system macosx python and switch to whatever new version of python you want available through pyenv.


I personally wouldn't mess around with OSX's python like they said. My personally preference for stuff like this is just using MacPorts and installing the versions I want via command line. MacPorts puts everything into a separate direction (under /opt I believe), so it doesn't override or directly interfere with the regular system. It has all the usually features of any package management utilities if you are familiar with Linux distros.

I would also suggest installing python_select via MacPorts and using that to select which python you want "active" (it will change the symlinks to point to the version you want). So at any time you can switch back to the Apple maintained version of python that came with OSX or you can switch to any of the ones installed via MacPorts.


Echoing above on not messing with OS X install. Have been faced with a couple of reinstalls thinking I could beat the system. The 3.1 install Scott Griffiths offers above works fine with Yosemite, for any Beta testers out there.. Yosemite has Python 2.7.6 as part of OS install, and typing "python3.1" from terminal launches Python 3.1. Same for Python 3.4 (install here).


Instal aws cli via homebrew package manager. It is the simplest and easiest method.

  1. If you dont have homebrew installed , enter this command in your terminal

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Next 'brew install awscli'

This will install aws cli on your mac


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to python-3.x

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7?