Problem-Solving: A Beginner-Friendly Story About Deep Learning and AI with TensorFlow and Python 3.4 on Mac OS

di.ai
Accel.AI
Published in
5 min readJul 26, 2017

This post is part story, part tutorial, part one of a short series.

It is my first real post on Medium, and I am going to try something a little different.

Instead of a how-to on installing a TensorFlow stack, I am going to write about problem-solving, which developers often call “debugging.” By the end of my story, I hope you — the new developer — will feel more confident about installing a TensorFlow stack, even if some of the requirements change and even if you use a different stack.

Yup. You can do this.

Why debugging? To me, the process of debugging used to be this abstract realm of wonder until I found myself just doing it as part of the process of my work. My debugging experience with Python 3 and TensorFlow while testing my first TensorFlow build feels like a smaller deal than I would have thought when I first started programming. Some of that is the problem-solving experience I now have in programming, but I hope describing the process will bring some perspective to new developers working with emerging software and stacks.

When I first started learning to program, I was trying to run Python using a Windows machine and kept getting stuck on the installation process. Most of the advice on the Internet was for and by Mac and Linux users. I also found the transition from Python 2 to Python 3 to be jarring. Mentors were teaching Python 3, and the rest of the world was working in Python 2.7. That was incredibly intimidating to me, and it took some outside intervention (including a guided switch to the Ubuntu Linux operating system) to get “unstuck.”

Now, in a world where most TensorFlow users are on Python 2.7, and Python has officially stopped supporting it, I hope this story-tutorial will make it less confusing to get started, even as the software is dynamic and transitioning.

The transition is always with us. That’s just tech. Some of you may have already installed some of or all of this software. In the process of digesting this story, perhaps debugging will become familiar enough to you that you can fill in what’s missing in the tutorials you find for this and other projects.

The Very Beginning: Installing Dependencies for Mac OS:

Install Hombrew with directions from this page.

Brew install Python 3. My installation uses Python 3.4. Literally, just type “brew install python3.4” after the “$” (no quotes) on the command line. It will look like this: $ brew install python3.4

Bug Number One: Did you notice how I just breezed by that instruction? Well actually, it took several steps to figure out that I should specify Python 3.4. I had already brew installed Python 3, which updated me to 3.6, but a few steps after the first two times I tried to install TensorFlow, I received all kinds of error messages. There was a bug. When I saw that there was a fix to that problem (thanks, Google!), I decided to focus on Python 3.4 for this installation.

So, bug fix number one was deciding on a version of Python 3 to use, discovering the solutions that came with it, and solving problems specific to Python 3.4. In another post, I will describe in greater detail how I landed on Python 3.4. But for now…

Install pip (a package manager that tells folders and files where to live on your systems) using “sudo easy_install pip.” It will look like this:

So there are few things you need to know: Easy_install is a package manager (like Homebrew), but your Mac might not let you make that change unless you type “sudo” in front of the command.

This is not a bug. It is a problem-solving opportunity related to the fact that I was using Python 3. I knew that pip3 existed, so my instinct was to use that. I tried it. It failed. I used sudo easy_install pip, and it worked.

Side note: LEARN ABOUT SUDO! It’s a very powerful command that overrides your computer’s default protective behaviors.

Install virtualenv, which is something like a walled-off operating system. It is inside your computer but segregated from the rest of your machine. I typed “sudo pip3 install --upgrade virtualenv” in the terminal. It worked.

If you look closely, you can see the next steps in creating a virtual environment, the machine-in-a-machine that you will use to run TensorFlow. Look at how clean those steps are! I like to read the last line, “wheel…done” as “well done.”

After that, all I had to do was build the virtual machine by typing the commands (borrowed from TensorFlow’s documentation page) in the first line of next screenshot. The list of installations is longer, but I think you get the idea.

I was happy to see that there was an actual upgrade for Python3 and documentation for reference. If that worked for you, you’re almost done installing! The story will continue with iPython/Jupyter Notebook, Scikit Learn, matplotlib, and Numpy.

The first part of this series focuses on installing TensorFlow and a few dependencies on a Mac operating system, but the following are also useful resources if you are getting started in A.I. on different systems.

Special thanks to Accel.ai — a career accelerator shaping the next generation of A.I. professionals and enthusiasts — for assembling this list.

Package Installation Instructions:

  1. Python — https://www.python.org/downloads/
  2. Anaconda — https://docs.continuum.io/anaconda/install/
  3. Jupyter Notebook — http://jupyter.readthedocs.io/en/latest/install.html
  4. Scikit Learn — http://scikit-learn.org/stable/install.html
  5. Tensorflow — https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html

Instructional videos for step by step installation guides:

Windows

  1. Introduction to Machine Learning with Python — Set up Instructions for Windows (python, numpy, matplotlib, scipy and scikit-learn)
  2. Install Anaconda, Jupyter Notebook, Spyder on Windows 10
  3. Installing TensorFlow — Installing CPU and GPU TensorFlow on Windows

Mac

  1. Introduction to Machine Learning with Python — Set up Instructions for Mac (python, numpy, matplotlib, scipy and scikit-learn)
  2. Installing Anaconda & iPython Jupyter Notebook on Mac OS X
  3. Installing TensorFlow — TensorFlow is supported by Mac and Linux, but not Windows. You can use their Docker distribution on Windows if you wanted.

--

--

di.ai
Accel.AI

Ethical Developer, A.I. Enthusiast, Python for Life