I am starting to learn Python because every machine learning tutorial these days seems to be focused on using Python. Python is great, but setting it up on a Mac can be a bit challenging since OS X wants to have its own specific version of not only Python but certain Python modules available globally. I tried different techniques like Anaconda, virtualenv, or manipulating the PATH environment variable, but the best way I have found so far is to run Docker with one of Python’s pre-built docker images that you can find on docker hub ( https://hub.docker.com/_/python/ ). Or perhaps you want to play around with Jupyter and scipy or tensorflow. You can run a pre-built docker image from https://github.com/jupyter/docker-stacks with all the necessary python modules pre-installed and ready to go.
If you aren’t familiar with Docker, there is a free OS X install image ( community edition ) available at https://store.docker.com. Once installed spend a few moments walking through the getting started documentation to get a feel for the syntax.
Recently I’ve been reading Hands-On Machine Learning with Scikit-Learn & TensorFlow. Using a few simple commands, I was able to spin-up a fully-loaded Jupyter server with almost no hassle. From my home directory, I typed the following and was off and coding along with the book. I didn’t have to struggle to setup a Python 3 environment and I didn’t have to use pip to install all the necessary modules. It was super easy to get started.
mkdir scikit-learn1 cd scikit-learn1 docker run -ti --rm -p 8888:8888 -v "$PWD":/home/jovyan/work jupyter/scipy-notebook
Anything I type into the Jupyter notebook is saved in scikit-learn1 directory. The docker command opens an interactive TTY, flags the docker image to be removed once it is terminated, binds the container port 8888 to the host port 8888, maps the current working directory to the container user’s home directory and runs the Dockerfile jupyter/scipy-notebook.
Once the container finishes spinning-up, a message in the console instructs me to paste a URL into my browser.
[C 23:46:11.592 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=6775924a7bfcb88b2e5f7469e93236a2387765c1ddd8ad9a
It’s that easy.