samx18.io

A Lightweight Install of Keras + Tensorflow on Mac

A Lightweight Install of Keras + Tensorflow on Mac

03 February 2020

There are few different ways to install Tensorflow and Keras on Mac, for instance you could install using the Anaconda and the Conda package manager or you could install install everything globally. However you could also go for a lightweight option and install both Tensorflow and Keras in virtual environment via the official pip & PyPi. The instructions here assume you already have Python and virtualenv installed

Virtual environment setup

The current versions of Tensorflkow and Keras (with Tensorflow as the backend) now have support for Python 3.7

Start off by creating a virtual environment with virtualenv and activating it.

~/S/m/ ❯❯❯ virtualenv tfk
~/S/m/ ❯❯❯ cd tfk
~/S/m/tfk ❯❯❯ source bin/activate

Tensorflow Install

Once the environment is active use pip to install tensorflow

(tfk) ~/S/m/tfk ❯❯❯ pip3 install tensorflow

Test the installation

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))

Keras Install

Now install Keras using pip in the activated virtual environment

(tfk) ~/S/m/tfk ❯❯❯ pip3 install keras`

Test the Keras installation

python -c 'import keras; print(keras.__version__)' 

Jupyter setup

You might have to reinstall jupyter in your virtual environment so you can load the Tensorflow and Keras packages that are only avilable via the virtual environment.

~/S/m/tfk ❯❯❯ pip3 install jupyter

Finally start jupyter and test everything works as expected from jupyter

Keras Jupyter

comments powered by Disqus