Reinstalling the Python machine learning environment in my Mac
That is conda and python 3.7, tensorflow, keras, numpy, pandas, jupyter, sklearn etc.
Something went wrong with my previous installation of Anaconda on an upgrade and I decided to reinstall it. Debugging it, would have probably taken more time (if possible at all), while a fresh start is always welcome as long as your code and data are secure. And the Anaconda installation is totally and easily replaceable. So straight to the steps:
Step 1: I removed my old installation
- The Anaconda folder was in
~/anaconda
so I did arm -rf anaconda3
while in my home folder. - I also removed an entry in my
~/.zshrc
Step 2: I installed Anaconda again
- Downloaded and run the installer for Python 3.7

- Followed the standard, as is installation. This would also install Anaconda paths on my zsh profile. And indeed it did (
tail -n 20 ~/.zshrc
):

- Anaconda installed at
~/opt/anaconda3
Step 3: I verified the installation
- From the Applications folder I opened the Anaconda Navigator (didn’t wait until it was indexed by Spotlight).
Step 4: I also opened a terminal and run a few commands
conda -V
conda list
python -V
python
and thenCtrl-D

- everything seems to be working
Step 5: I updated conda
to latest version (and not all the packages)
conda update conda
(this tookconda
from 4.8.2 => 4.8.3)- I didn’t update all the packages to their latest version. Basically I followed the advice from here and the section “Why Updating the Anaconda Package is Almost Always a Bad Idea”. It is a fresh install and if I need to update any package down the road I will do so individually and for a reason.
Step 6: I ensured that the basic libraries I want are installed from a script in this Machine Learning Mastery blog post:
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
# numpy
import numpy
print('numpy: %s' % numpy.__version__)
# matplotlib
import matplotlib
print('matplotlib: %s' % matplotlib.__version__)
# pandas
import pandas
print('pandas: %s' % pandas.__version__)
# statsmodels
import statsmodels
print('statsmodels: %s' % statsmodels.__version__)
# scikit-learn
import sklearn
print('sklearn: %s' % sklearn.__version__)
# tensorflow
import tensorflow
print('tensorflow: %s' % tensorflow.__version__)
# keras
import tensorflow.keras
print('keras: %s' % tensorflow.keras.__version__)
I have created a gist for that so:
- git clone https://gist.github.com/848a30b3ede1be71dfcbd032d7c6cd3e.git
- cd 848a30b3ede1be71dfcbd032d7c6cd3e
- python confirm-ml.py

The standard machine learning libraries I wanted are installed in the base environment so what’s left is to also add TensorFlow to complete the installation. But before that I’ll check also that Jupyter notebooks are running.
Step 6: Check Jupyter notebooks
From the command line with jupyter notebook
I saw the Jupyter environment in my browser (http://localhost:8888/tree
) and I was able to also create a new notebook in Python 3.
Step 7: Clone the base environment and create a new one for tensorflow
So now the idea is to create a new environment for TensorFlow, but in addition keep the base packages. To do that I cloned the base env:
conda create -n tf — clone base

Step 8: Install TensorFlow (and Keras)
After activating the tf
environment with conda activate tf
the next step was to install TensorFlow in that environment. I did that with conda install tensorflow
.

I installed it from conda instead of tensorflow due to the extra speed-ups provided by the the conda TensorFlow packages are built using the Intel® MKL-DNN library,
As for Keras, it is included in TensorFlow and as recommend by the keras team:
At this time, we recommend that Keras users who use multi-backend Keras with the TensorFlow backend switch to
tf.keras
in TensorFlow 2.0.
Step 9: Testing
To ensure everything is working as planned (1) I re-run the config-ml.py
script:

Check!
And (2) I created a notebook and “copied-pasted” this example changing:
from keras…
to from tensorflow.keras…

The example run smoothly:

Check!
Since the Mac I have is old with no GPU (upgraded MacBook Pro late 2012) I stopped and this point.