If you already have python 2 on your mac, can you install python 3?

If you already have python 2 on your mac, can you install python 3?

Mac OS X comes with Python 2.7 out of the box.

You do not need to install or configure anything else to use Python 2. These instructions document the installation of Python 3.

The version of Python that ships with OS X is great for learning, but it’s not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version.

Doing it Right¶

Let’s install a real version of Python.

Before installing Python, you’ll need to install GCC. GCC can be obtained by downloading Xcode, the smaller Command Line Tools (must have an Apple account) or the even smaller OSX-GCC-Installer package.

Note

If you already have Xcode installed, do not install OSX-GCC-Installer. In combination, the software can cause issues that are difficult to diagnose.

Note

If you perform a fresh install of Xcode, you will also need to add the commandline tools by running xcode-select --install on the terminal.

While OS X comes with a large number of Unix utilities, those familiar with Linux systems will notice one key component missing: a package manager. Homebrew fills this void.

To install Homebrew, open Terminal or your favorite OS X terminal emulator and run

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

If you have OS X 10.12 (Sierra) or older use this line instead

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Now, we can install Python 3:

This will take a minute or two.

Pip¶

Homebrew installs pip pointing to the Homebrew’d Python 3 for you.

Working with Python 3¶

At this point, you have the system Python 2.7 available, potentially the Homebrew version of Python 2 installed, and the Homebrew version of Python 3 as well.

will launch the Homebrew-installed Python 3 interpreter.

will launch the Homebrew-installed Python 2 interpreter (if any).

will launch the Homebrew-installed Python 3 interpreter.

If the Homebrew version of Python 2 is installed then pip2 will point to Python 2. If the Homebrew version of Python 3 is installed then pip will point to Python 3.

The rest of the guide will assume that python references Python 3.

# Do I have a Python 3 installed?
$ python --version
Python 3.7.1 # Success!

Pipenv & Virtual Environments¶

The next step is to install Pipenv, so you can install dependencies and manage virtual environments.

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

So, onward! To the Pipenv & Virtual Environments docs!


This page is a remixed version of another guide, which is available under the same license.

If you already have python 2 on your mac, can you install python 3?

Python is a popular programming language that is widely used by beginners and longtime developers alike. Modern Mac OS versions come with Python 2.7.x installed (or Python 2.6.1 if an older Mac OS X version), but many Python users may need to update Python in Mac OS to a newer version like Python 3.8.x or newer.

This article will discuss how to get an updated Python 3 installation on the Mac by covering two different ways to quickly and easily install Python 3 onto a Mac.


Note that we said install Python 3, not update to Python 3, because how this will work is installing Python 3 while simultaneously maintaining Python 2 on the Mac. This is essential because apparently some Mac apps rely on Python 2 support, so if you attempt to upgrade Python 2.x to Python 3.x in Mac OS you will eventually find that something is broken, perhaps critically so. With that in mind you should not attempt to update the existing preinstalled Python release on a Mac, instead you will just have a co-installation of Python 3 for full compatibility.

And yes, Python 3 and Python 2 can coexist on a Mac without any conflict, the usage commands will just be slightly different.

How to Install Python 3 in Mac OS

Perhaps the simplest way to install Python 3 is by using the Python package installer from python.org

  1. Go to Python.org downloads page here and download the latest Python installer package
  2. Run the Python installer package and install Python 3 onto the Mac
  3. If you already have python 2 on your mac, can you install python 3?

Python 3.8.x requires about 100mb of disk space to install. Installation is quick, and you’ll have Python 3.x alongside Python 2.x on the Mac.

Once Python 3 is installed you will find a Python3 folder within the /Applications directory of your Mac. You’ll also find the simple IDE called IDLE within the /Applications/MacPython3/ directory, which basically gives you the same Python IDE you’d encounter if you ran ‘python3’ at the command prompt in Terminal.

You can also install Python 3.x on a Mac through Homebrew, which is my preferred method as a Homebrew user.

How to Install Python 3.x with Homebrew

Installing an updated version of Python 3.8 (as of time of writing) is super easy with HomeBrew. Of course you will need Homebrew installed on the Mac before you can use the Homebrew method, but if you’re interested in messing around with Python then Homebrew will probably appeal to you anyway.

We’re going to assume you already have Homebrew, if you don’t the you can read here how to install Homebrew on Mac OS.

To install the latest version of Python 3 using Homebrew, just issue the following command string:

brew install python3

Once the updated Python 3 has been installed on the Mac, you can run it with:

python3

Whether you install the updated Python 3 with the package installer or Homebrew, the default version of Python 2.7 that comes preinstalled with Mac OS and Mac OS X will still be installed, completely untouched, and can be run with the simple “python” command as always.

How to Check What Version of Python is Currently Installed in Mac OS

From the Terminal application, simply typing the following command will report back what version of Python is currently installed:

python --version

In MacOS, you will find it’s typically Python 2.7.x of some variation, either 2.7.4 or 2.7.10 or similar.

After you have installed Python with Homebrew or with the package installer, you can check the updated new version of Python with:

python3 --version

And as mentioned before, both installations of Python will coexist without conflict.

If you already have python 2 on your mac, can you install python 3?

You can also find out where each version of python is installed with the ‘which’ or ‘whereis’ command:

If you already have python 2 on your mac, can you install python 3?

Note that some aspects of Python are different in each version, and even features like the instant Python simple web server trick is different from version 2 to version 3. If you’re planning on using something longterm, or learning in general, you’ll be better off writing in Python 3.x rather than the older Python 2.x releases.

So now that you’ve got Python 3 installed, you’re ready to roll!

Learning Python, and Python Resources

If you’re new to Python and programming in general, there are a variety of great resources out there to get you started.

If you’re the type to enjoy learning from a book, some popular choices are the following (these are affiliate links to Amazon):

  • Learning Python – O’Reilly
  • Python Crash Course: A Hands-On, Project-Based Introduction to Programming
  • Automate the Boring Stuff with Python: Practical Programming for Total Beginners

You can check out free online courses too, including these from MIT:

  • edX: MIT Learn Python course
  • MIT: Intro to Computer Science course

Or you can also explore the broad Python Wiki resources page here too.

TLDR: Don’t Update Python 2.x to Python 3.x, Just Install Python 3.x on the Mac

TLDR: Don’t update the preinstalled Python 2.x to Python 3.x, it will likely break something in doing so. Instead, just install and run the updated Python 3 separately.

How do I upgrade Python 2 to Python 3 Mac?

Check Python Version..
Change the bash Shell to Zsh shell..
Confirm whether your bash is converted to zsh shell..
Installing XCode..
Installing the Command Line Tool..
Installing HomeBrew Package Manager..
Installing Python..
Python 3 Path..

Can I install Python 2 and Python 3?

We can have both Python 2 and Python 3 installed on any Windows or Linux device. We can either create different environments on different IDEs to use the versions separately or use the following ways to run them using the command prompt.

Can I have multiple versions of Python installed on Mac?

With pyenv you can install multiple Python versions on your machine and easily switch between them. Note: this article is geared towards Mac users, and especially Apple Silicon Mac users. Linux users might benefit from the pyenv tutorial, but Windows users are out of luck — pyenv does not officially support Windows.

How do I add Python 3 to my Mac?

The complete path of the Python (or Python3) UNIX executable can be added (for OS X 10.8 Mountain Lion and up) by: Opening the Terminal and entering the command: sudo nano /etc/paths . Enter your password when prompted to do so. A list of directories that are currently a part of the PATH variable will appear.