It can be difficult to install a python machine learning environment on Mac OS X.
Python itself must be installed first, and then there are many packages to install, and it can be confusing for beginners.
In this tutorial, you will discover how to setup a Python 3 machine learning and deep learning development environment using macports.
After completing this tutorial, you will have a working Python 3 environment to begin learning, practicing, and developing machine learning and deep learning software.
Let’s get started.

How to Install a Python 3 Environment on Mac OS X for Machine Learning and Deep Learning
Tutorial OverviewThis tutorial is broken down into the following 4 steps:
Install XCode Tools Install Macports Install SciPy Libraries Install Deep Learning Libraries 1. Install XCodeXCode is the IDE for development on OS X.
Installation of XCode is required because it contains command line tools needed for Python development. In this step, you will install XCode and the XCode command line tools.
This step assumes you already have an Apple App Store account and that you have sufficient administrative privileges to install software on your workstation.
1. Open the “ App Store ” application. Search for “ XCode ” and click the “ Get ” button to install.You will be prompted to enter your App Store password.
XCode is free and is at least 4.5 GB in size and may take some time to download.

App Store Search for XCode
2. Open “ Applications ” and then locate and start “ XCode “.You may be prompted with a message to install additional components before XCode can be started. Agree and install.

Install Additional XCode Components
3. Install the XCode Command Line Tools, Open a terminal window and type: xcode-select --installA dialog will appear and install required tools.
Confirm the tools are installed by typing:
xcode-select -pYou should see output like:
/Applications/Xcode.app/Contents/Developer 4. Agree to the license agreement (if needed). Open a terminal window and type: xcodebuild -licenseUse the “ space ” key to navigate to the bottom and agree.
You now have XCode and the XCode Command Line Tools installed.
2. Install MacportsMacports is a package management tool for installing development tools on OS X.
In this step, you will install the macports package management tool.
1. Visit macports.org 2. Click the “ Download ” button at the top of the page to access the install page . 3. Download the “ macOS Package (.pkg) Installer ” for your version of OS X.At the time of writing, the latest version of OS X is Sierra.

Macports Package Installation
You should now have a package on your workstation. For example:
MacPorts-2.3.5-10.12-Sierra.pkg 4. Double click the package and follow through the wizard to install macports.
Macports Installation Wizard
5. Update macports and confirm the system is working as expected. Open a terminal window and type: sudo port selfupdateThis will update the port command and the list of available ports and is useful to do from time to time.
You should see a message like:
MacPorts base is already the latest version 3. Install SciPy and Machine Learning LibrariesSciPy is the collection of scientific computing Python libraries needed for machine learning development in Python.
In this step, you will install the Python 3 and SciPy environment.
1. Install Python version 3.5 using macports. Open a terminal and type: sudo port install python35To make this the default version of Python, type:
sudo port select --set python python35 sudo port select --set python3 python35Close the terminal window and reopen it.
Confirm that Python 3.5 is now the default Python for the system by typing:
python -VYou should see the message below, or similar:
Python 3.5.3 2. Install the SciPy environment, including thelibraries: NumPy SciPy Matplotlib Pandas Statsmodels Pip (package manager)Open a terminal and type:
sudo port install py35-numpy py35-scipy py35-matplotlib py35-pandas py35-statsmodels py35-pipThis may take some time to download and install.
To ensure pip for Python 3 is the default for the system, type:
sudo port select --set pip pip35 3. Install scikit-learn using pip. Open the command line and type: sudo pip install -U scikit-learn 4. Confirm the libraries were installed correctly. Open a text editor and write (copy-paste) the following script: # scipy importscipy print('scipy: %s' % scipy.__version__) # numpy importnumpy print('numpy: %s' % numpy.__version__) # matplotlib importmatplotlib print('matplotlib: %s' % matplotlib.__version__) # pandas importpandas print('pandas: %s' % pandas.__version__) # statsmodels importstatsmodels print('statsmodels: %s' % statsmodels.__version__) # scikit-learn importsklearn print('sklearn: %s' % sklearn.__version__)Save the script with the filename versions.py .
Change directory to the location where you saved the script and type:
python versions.pyThe output should look like the following (or similar):
scipy: 0.18.1 numpy: 1.12.0 matplotlib: 2.0.0 pandas: 0.19.2 statsmodels: 0.6.1 sklearn: 0.18.1What versions did you get?
Paste the output in the comments below.
You can use these commands to update machine learning and SciPy libraries as needed.
Try a scikit-learn tutorial, such as:
Your First Machine Learning Project in Python Step-By-Step 4. Install Deep Learning LibrariesIn this step, we will install Python libraries used for deep learning, specifically: Theano, TensorFlow, and Keras.
1. Install the Theano deep learning library by typing: sudo pip install theano 2. Install the TensorFlow deep learning library by typing: sudo pip install tensorflow 3. To install Keras, type: sudo pip install keras 4. Confirm your deep learning environment is installed and working correctly.Create a script that prints the version numbers of each library, as we did before for the SciPy environment.
# theano importtheano print('theano: %s' % theano.__ver