Being a software engineer, you often come across many instances where you would require to have Python installed on your Mac.
However, the issue is most modern macOS versions come with rather with Python 2.7.x installed and not the newer, modern version like Python 3.6.5 or Python 3.7.2 (which is the most up-to-date version right now).
Setting Python 3.6.5 on the Macintosh 2 Installing Python 3.6.5 3on Macintosh 2F2, 3F Installing Python 3.6.5 4on Mac OS X is somewhat simpler than in previous years. However, packages such as numpy and matplotlib need to be installed from a networked source, just as with Windows installations. First, create a folder on your desktop — for example, Python-files — and download the fol. Any kind of OS (Windows, Linux or Mac) Python version 3.5 or higher. Keras is python based neural network library so python must be installed on your machine. If python is properly installed on your machine, then open your terminal and type python, you could see the response similar as specified below. The only prerequisite for NumPy is Python itself. If you don’t have Python yet and want the simplest way to get started, we recommend you use the Anaconda Distribution - it includes Python, NumPy, and other commonly used packages for scientific computing and data science. NumPy can be installed with conda, with pip, or with a package manager on macOS and Linux. NumPy doesn’t depend on any other Python packages, however, it does depend on an accelerated linear algebra library - typically Intel MKL or OpenBLAS. Users don’t have to worry about installing those, but it may still be important to understand how the packaging is done and how it affects performance and behavior users see.
This short guide is written to show you how to properly install Python 3 on a Mac OS Xcomputer.
Before you jump into the guide, do take note that there are multiple ways to install Python 3 on a Mac but with this guide, I’ll show you the two easiest ways to do this, step-by-step.
There's a bug that's been introduced with an interaction between python 3.6, numpy, and the version of scikit-image that's pinned here. This should fix that, and AFAICT `skimage` actually isn't used in the notebooks, so this upgrade shouldn't be breaking yeah?
Personally, the way I did it was using a package manager like HomeBrew (it’s okay if you don’t understand what it is). Again, I’ll show you how to do this method down below.
Wait, how do I check if Python 3 is already installed on my Mac?
Simple. Open up your Terminal and type the following line python --version
and then hit your Enter key:
You should see the python version that is currently installed on your Mac.
How to Install Python 3 on macOS: 2 Ways
1. The Simplest Way.
Perhaps the simplest way to install Python 3 on macOS.
This is for you especially if you’re a newbie (though I still strongly recommend you try the HomeBrew method below) or if you don’t want to deal with copy-pasting code into your Terminal and downloading other software.
Here’s how to install Python 3 on your macOS:
- Jump into Python.org downloads page and simply just download the latest Python version.
- Next, run the Python Installer to install Python 3 onto your Mac.
Note
The Python installation may require about 100MB of disk space to install. Once you’ve installed Python 3 you can have it alongside Python 2 without having to delete the latter from your Mac.
- Great! Now once Python 3 is installed, you’ll be able to find it within the Applications directory of your Mac. You’ll also find here a simple IDE called “IDLE.app” which gives you a basic Python IDE.
Help! Where do I find the Applications directory?
If you can’t find the Applications directory, simply go to Finder by clicking the Finder icon in the Dock (it’s usually the first icon from the left side of the Dock). From there simply, go to the Go menu and select Applications.
Done. If you got yourself lost through the process, you can comment down below.
Next up, I’ll show you how you can install Python 3 using HomeBrew onto your macOS. This is my preferred way and it is just as simple as the method before but it will make your life a whole lot simpler, in the long run, using Python.
2. Install Python 3 on Mac using HomeBrew.
This method is dead-ass simple and a little fun. 🙂
First of all, you’ll need to have this thing called HomeBrew installed on your Mac. Homebrew is basically a “package manager”. A package manager is an application that helps you install the stuff you need that Apple (or even your Linux System) hadn’t installed in the first place for you.
It’s simple, fast and safe.
Second, you will need to have installed XCode onto your Mac. If you’re thinking of learning how to program or creating iOS apps on your Mac, then it’s good to have XCode installed. We will be using XCode to install HomeBrew application.
How To Install Numpy
Note
If you have already installed XCode onto your Mac you can skip step 1 and jump straight to step 3.
Here are the steps to install XCode, HomeBrew as well as install Python 3 using HomeBrew onto your Mac:
- Jump into your Terminal app on your Mac and run the copy/paste the following command into the Terminal to install XCode onto your Mac:
- Simply click through all the confirmation crap that XCode shows. It may take a little while to install XCode since it is a large program.
- Great! Now that you have XCode installed, you can install HomeBrew! To install HomeBrew, simply copy/paste the following command into your Terminal:
Note
You can confirm the HomeBrew installed correctly by running the command: below:
- You’ve installed HomeBrew! Now let’s install the Python 3, the reason why you’re here. To install the latest version of Python, just copy/paste the following command into your Terminal:
Note
You can confirm which version of Python was installed all by running the command below (the exact same command you tried earlier in this guide). It should show up as follows:
- Finally, let’s run our new Python 3. Simply enter
python3
.
Voila! You have now installed Python 3 successfully if you see something similar in your Terminal:
Bonus
•If you want to exit, type exit()
and then hit your Return button on your keyboard. You can also hit both Control and D keys at the same time instead of the Return key.
•Remember I mentioned you can run both your new Python 3 alongside your old Python 2? Yup. Simply type python
into the Terminal to run with Python 2.
Share this guide with someone who’s looking to install Python 3 on macOS.
Posted on October 4, 2016 by Paul
Updated 26 January 2020
In this article, I will show you how to install Python 3 with NumPy, SciPy and Matplotlib on macOS Catalina.
There is also a video version of this tutorial:
MacOS comes by default with Python 2.7 which, at this point, receives only bug fixes and will be EOL by 2020. Python 3.x is the future and it is supported by all major Python libraries. In this tutorial, we’ll use Python 3.8.
Start by installing the Command Line Tools for macOS. Please note, that you will need the Command Line Tools even if you’ve already installed Xcode. Open a Terminal and write:
Once the Command Line Tools are installed, we can install Python.
The official installer of Python is a pkg file that will start a GUI installer which will guide you through the installation. You can also check the video version of this tutorial if you want to see how I did it.
As a side note, you can have multiple Python 3 versions installed on your macOS machine. If this is the case, you can select which version you want to use by specifying the version number, e.g.:
or:
After the above, you can invoke Python 3.8 using the python3.8 command. python3 will also invoke the latest installer version of Python 3. This is what I see if I run python3.8 on my machine:
Next, let’s follow best practices and create a new Python environment in which we can install NumPy, SciPy and Matplotlib:
At this point, your prompt should indicate that you are using the work environment. You can read more about Python environment in the documentation.
Once an environment is activated, all the install commands will apply only to the current environment. By default, if you close your Terminal, the environment is deactivated. If you want to be able to use it, use the source work/bin/activate command.
We can install NumPy, SciPy and Matplotlib with:
As a side note, when you are in an active environment you can use the python command to invoke the Python interpreter, no need to use the version number.
Fire up Python, import scipy and print the version of the installed library. This is what I see on my machine:
Let’s try something a bit more interesting now, let’s plot a simple function with Matplotlib. First, we’ll import SciPy and Matplotlib with:
Next, we can define some points on the (0, 1) interval with:
Now, let’s plot a parabola defined on the above interval:
You should see something like this:
As you’ve probably noticed, plt.show() is a blocking command. You won’t be able to use the interpreter until you close Figure 1.
Numpy Package In Python
There is also an interactive mode in which you can plot functions. Close Figure 1 and write:
This is what you should see:
At any point you can disable the interactive plot mode with:
after which you will need to use the plt.show() function in order to actually see the result of the plt.plot function.
If you want to learn more about Python and Matplotlib, I recommend reading Python Crash Course by Eric Matthes. The book is intended for beginners, but has a nice Data Visualization intro to Matplotlib chapter:
Another good Python book, for more advanced users, which also uses Matplotlib for some of the book projects is Python Playground by Mahesh Venkitachalam: