Use Anaconda, NumPy, Scikit-learn, Spyder and other machine learning tools with Apple Silicon

Raffaele Pojer
4 min readMar 14, 2021

I am a student of a master in AI, having to purchase a new laptop in the period were the hype of the new Apple Silicon was at its maximum. Obviously, I decided to buy a MacBook Pro with the new M1 chip. Before buying it, I was a Windows/Linux user, and I never had an Apple device, let alone a new Arm Mac…

These new laptops are blazing fast, last many hours, and in 4 months of use, I heard the fan spin only in a very occasional moment (most of the time was some stress test on purpose). The developer community is trying to deploy the new Arm version of their products faster as they can, but not all the software are ready, and a few more settings are needed to run some applications (hoping they will work).

As most users are trying to do, I will use as much native application as I can.

In this guide, I want to share the steps I use to install the applications and packages I need to use in my development sessions.
I’m not an expert, and for this reason, I am really open to any suggestion to improve this guide.

In this tutorial I will use Homebrew which now is native for Apple Silicon.

Install Anaconda for machine learning tools

If you need to use: scikit-learn, NumPy, PyTorch and other packages used in machine learning, we will use the miniforge repository form conda-forge. This repository contains the native packages compiled for Apple Silicon (I think they are not totally tested, but they seems to work fine).

You can install the Anaconda-Navigator through the graphical installer

Follow the on-screen instructions and Anaconda will be installed on your machine.

From now on, conda will be running under Rosetta 2, and it can be used without any problem.

Use native tools

Here comes the specific part for Apple Silicon:

Create a new environment dedicated to the native packages. Open your terminal app and type:

CONDA_SUBDIR=osx-arm64 conda create -n native python=3.9 -c conda-forge --override-channels

This command will create a new environment called native, with python 3.9 which is compiled for this M1 chip.

Activate this environment with:

conda activate native

To prevent that in this environment the packages choose a x64 channel by default:

conda env config vars set CONDA_SUBDIR=osx-arm64

Now, if you have to install some packages in the native environment you have to specify the conda-forge channel.

For example to install scikit-learn the command that you need is:

(with the native environment activated)

conda install scikit-learn -c conda-forge

Check if in the output the channel include at least osx-arm64.

Spyder developer tool

With Anaconda-Navigator comes Spyder, but I notice that it is running really slowly (probably is the Rosetta 2 translation). For this reason, I installed the Spyder stand-alone version with brew:

brew install --cask spyder

This stand alone version is running under Rosetta 2 too, but it is much faster.

Use the conda environment with Spyder:

To use Spyder with the specific conda native environment:

First activate the native environment, then install the spyder-kernels:

conda install spyder-kernels -c conda-forge

Print the environment PATH:

python -c “import sys; print(sys.executable)”

Copy the PATH and open Spyder.

Go to Spyder > Prefernces…

Click on Python interpreter and Use the following Python interpreter and paste the PATH of the environment just mentioned.

Restart the kernel or open/reopen Spyder, and you should be able to use Spyder with the native tools.

Update the packages

If you need to update the packages of your native environment without override them with the x64 channel packages, activate the environment and type:

conda update -c conda-forge --all

This command will update all the packages in the native environment.

Hope this will be useful to someone

Thanks for reading this :)

--

--

Raffaele Pojer

ICT — Artifical Intelligence Systems student at University of Trento. Mentor @coderdojo — Tech enthusiat