How to install Numpy and Pandas for data science in a M1 MacBook

The new M1 chip MacBooks come with a nasty surprise for those of us who like to tinker with code, specially Python science packages.

Failed to build Numpy
Failed to build Pandas

These 2 are pretty necessary in order to work with the Trading Tools I’m developing on this serie (Interactive Brokers API + Python), so it became necessary as well to test and explain how to install everything to make it work properly.

I won’t fake that I understand all the details of what’s going on with the whole GitHub thread because I’m far from it, however in a nutshell these modules are not working by default because of the different M1 chip architecture, and some extra tools and workarounds are necessary to install Numpy and Pandas ( as well other modules, if you happen to see the same error when working on something else).

After many hours wasted and much trial and error, the following 2 workflows worked for me:

How to install Numpy in a M1 MacBook:

pip3 install Cython
pip3 install --no-binary :all: --no-use-pep517 numpy
pip3 install pandas
pip3 install ib_insync

Source: Original StackOverflow thread.

How to install Pandas in a M1 MacBook:

python3 -m pip install virtualenv
virtualenv -p python3.8 venv
source venv/bin/activate
pip install --upgrade pip
pip install numpy cython
git clone https://github.com/pandas-dev/pandas.git
cd pandas
python3 setup.py install

Source: Original StackOverflow thread.

With that you should be able to use both modules in your projects!

Leave a Reply