48

I recently got a new MacBook Air M1, but I’m having trouble installing Pandas, since prebuilt binaries are not available for macOS/arm64. How can I install Pandas on an Apple Silicon Mac?

Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
Dan Hendrickson
  • 497
  • 1
  • 4
  • 3
  • 2
    I shouldn't have to ask (i.e., this should already be in your question), but what's the trouble? – cs95 Dec 01 '20 at 03:31

12 Answers12

62

Maybe it is too late. But the only solution worked for me is installing from source if you do not want to use rosetta2 or moniconda

python3 -m pip install virtualenv
virtualenv -p python3.8 venv
source venv/bin/activate
pip install --upgrade pip
pip install numpy cython
git clone --depth 1 https://github.com/pandas-dev/pandas.git
cd pandas
python3 setup.py install
tyron
  • 3,715
  • 1
  • 22
  • 36
rapoma
  • 621
  • 5
  • 4
  • 2
    This did not work for me. I'm running Big Sur on an M1 Mac and I got the error "Failed to build numpy. ERROR: Could not build whells for numpy which use PEP 517 and cannot be installed directly." – Jim Apr 12 '21 at 00:13
  • 1
    I think for python3.8, you should not have this error. For python3.9, tho you just use the hint from the error, install from source git clone https://github.com/numpy/numpy.git && cd numpy && python3 setup.py install – rapoma Apr 20 '21 at 21:51
  • Genius, saved my day also for numpy and scikit learn for Django, thanks – Hvitis Apr 25 '21 at 19:24
  • Thanks this totally helped, spent 4 and 1/2 hours trying to fix this problem. Much blessed for this knowledge. – Jackstine Jun 03 '21 at 02:39
  • 1
    Dis not work for me, still got the same error: ```venv/lib/python3.8/site-packages/pandas-1.4.0.dev0+264.g9c0a1ebec6-py3.8-macosx-11.4-arm64.egg/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture``` – NullPointer Jul 22 '21 at 06:18
  • this did work for me on a new Mac Book Pro running Monterey on M1 architecture. I am using pyenv. First, installed latest python 3.8. Then created a virtual environment from that. In that virtual environment I ran the installs and build above. – TomU Dec 24 '21 at 23:24
  • @Jim Re: PEP517 - see https://stackoverflow.com/a/69089320/1021819 – jtlz2 Mar 15 '22 at 07:08
30

What works for me:

pip3 install cython
OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 pip3 install numpy --no-use-pep517
OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 pip3 install pandas --no-use-pep517
Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
  • I am in arm64 mode. This did not work with Python 3.9.x, but it DID work with Python 3.8.11. Thank you. – George Campbell Jan 10 '22 at 02:00
  • Worked for me using Python 3.9.x trying to install numpy==1.20.0 which was required for scikit-learn. I had earlier tried with the OPENBLAS export thingy but it did not work. What worked was adding --no-use-pep517 along with installing cython. – Saheel Godhane Jun 01 '22 at 12:18
26

There are two methods to do this. But the underlying process is the same in both.

Method-1

Open a terminal window. Run arch. The result should be arm64. Now do arch -x86_64 zsh. This will create a x86 emulated zsh session inside the terminal. Now if you run arch command, the result should be i386.

Now do pip install pandas or pip3 install pandas (whichever command has the correct version). And this will work. Perform exit command to exit the emulated zsh session.

You can also execute a single command under x86 emulation without creating an emulated zsh session. Run arch -x86_64 pip install pandas. This will run pip command under x86_emulation but the terminal stays in the native arm environment.


Method-2

Open Terminal App using Rosetta 2 which emulates a x86 environment. Then do pip install pandas or pip3 install pandas (whichever command has the correct version) And that should work.

This trick would work for almost all the python packages that fails to install when tried in ARM architecture


Opening Terminal app using Rosetta 2

  1. Close the Terminal Application
  2. Find the Terminal App in Finder (usually located in Macintosh HD/Applications/Utilities)
  3. Secondary Click the Terminal Icon >> Get Info
  4. Check the checkbox labeled Open Using Rosetta
  5. Now launch a Terminal window (The new Terminal window will be opened using Rosetta emulation)

Edit-1: If you install a package under x86 emulation, you have to run your python code also under x86 emulation. If you try to run python in the native ARM environment, then architecture mismatch error will be thrown by the package for which you installed the x86 version.

14

Most of these articles fail to address the issue of 'not' wanting to run under Rosetta. Apple's TensorFlow fork works in native M1 mode, but there is no Pandas to match that. If you choose to run under Rosetta then you won't be able to find a matching TensorFlow. It's a lose lose situation.

10 Rep
  • 2,217
  • 7
  • 19
  • 33
Ashkan
  • 205
  • 1
  • 2
  • 8
  • Not true if you are using (mini)conda. You can use `conda install` which does seem to work. – Gerard Mar 08 '21 at 10:17
11

You can just uset the --no-use-pep517 flag, and you can install pandas with no problems.

Here is how I installed on my laptop:

~/Documents/projects/m-proj                                                                                                                                               
❯ pip install cython --no-use-pep517 
Collecting cython
  Using cached Cython-0.29.22-py2.py3-none-any.whl (980 kB)
Installing collected packages: cython
Successfully installed cython-0.29.22

~/Documents/projects/m-proj                                                                                                                                               
❯ pip install numpy --no-use-pep517
Collecting numpy
  Using cached numpy-1.20.1.zip (7.8 MB)
Using legacy 'setup.py install' for numpy, since package 'wheel' is not installed.
Installing collected packages: numpy
    Running setup.py install for numpy ... done
Successfully installed numpy-1.20.1

~/Documents/projects/m-proj                                                                                                                                           
❯ pip install pandas --no-use-pep517
Collecting pandas
  Using cached pandas-1.2.3.tar.gz (5.5 MB)
Collecting python-dateutil>=2.7.3
  Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Requirement already satisfied: pytz>=2017.3 in ./venv-trans/lib/python3.9/site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in ./venv-trans/lib/python3.9/site-packages (from pandas) (1.20.1)
Requirement already satisfied: six>=1.5 in ./venv-trans/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Using legacy 'setup.py install' for pandas, since package 'wheel' is not installed.
Installing collected packages: python-dateutil, pandas
    Running setup.py install for pandas ... done
Successfully installed pandas-1.2.3 python-dateutil-2.8.1
Dragos Vasile
  • 453
  • 4
  • 12
  • 2
    This works for me with `numpy-1.20.1` but not with `numpy-1.20.2` which is required for python3.9. A bit of an impass, that seems super time dependent as right now I can install python3.9 in on M1 (arch arm64) with pyenv, but not python3.8. It would be nice to get python _and_ pandas on arm64. – PeterK Apr 02 '21 at 01:46
  • This worked for my with m2 mbp and numpy~=1.19 pandas~=1.1 – Q. Qiao Aug 30 '22 at 13:33
6

Miniconda is by far the simplest option.

brew install --cask miniforge
conda create -n myenv python=3.8
conda init zsh
conda activate
conda install pandas

If you need an older version (not available for arm64 in conda-forge)

brew install --cask miniforge
conda create -n myenv python=3.8
conda init zsh
conda activate
pip install cython
curl -L https://github.com/pandas-dev/pandas/archive/v1.1.2.zip --output pandas.zip  
unzip pandas.zip     
cd pandas-1.1.2 
python3 setup.py install
rm pandas.zip
rm -rf pandas-1.1.2
Defenestrator6
  • 405
  • 1
  • 6
  • 10
5
  1. Install conda miniforge for OS X arm64(Apple Silicon)

https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh

  1. Then create virtual environment and install your required package conda create -n myenv python=3.6 conda activate myenv conda install numpy conda install pandas
autitya
  • 71
  • 5
  • Great. I think Miniforge is the way to go. Was reading Pandas in Action and their advice was to go with Anaconda. Anaconda Apple Silicon page is just way too confusing! – JGFMK Apr 15 '22 at 11:16
4

Check out this article Apple M1 — Matplotlib, Python, and Jupyter Lab or this one (same author) Apple M1, Python, Pandas, and Homebrew

Maybe you just need run terminal with Rosetta (the second article indicates this)

wizarpy_vm
  • 396
  • 1
  • 2
  • 10
  • The article basically just says tick "Start with Rosetta" for iTerm2. That didn't help me. – Ben Butterworth Feb 17 '21 at 10:04
  • Update March 8-2022: Macbook with M1 and MacOS Monterey. The approach that worked for me still was opening `zsh` in rosetta mode and following the regular installation procedures. The virtual-env approach wasn't still working out for me the – Vipin Menon Mar 08 '22 at 15:03
4

So I found the solution. Apparently even though I checked the box to open the term using Rosetta, it didn't do it the first time. I finally discovered this by executing "arch" on the term, which returned "arm64", not "i386". Rebooting apparently made the "rosetta" selection stick, and I was then able to "pip3 install pandas" successfully. Of course it would have been nicer to install it in native arm mode. Thanks to all for the pointers.

Dan H.
  • 41
  • 1
  • Different, but related question: do you have any advice on how to install tensorflow? "pip3 install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.4.0-cp38-cp38-macosx_10_14_x86_64.whl" returns "ERROR: tensorflow-2.4.0-cp38-cp38-macosx_10_14_x86_64.whl is not a supported wheel on this platform." – user505117 Dec 16 '20 at 22:14
3

reference this page https://ittone.ma/ittone/python-install-pandas-on-mac-m1-big-sur-into-multiple-virtualenv/

  1. pip install cython
  2. git clone https://github.com/numpy/numpy.git
  3. cd numpy
  4. python3 setup.py install
  5. git clone https://github.com/pandas-dev/pandas.git
  6. cd pandas
  7. python3 setup.py install
zen ko
  • 31
  • 1
  • When I tried these steps, everything worked until step 7 when I receive an error: ModuleNotFoundError: No module named 'numpy' – most200 Jul 14 '22 at 05:46
1

I noticed that many of the users including myself ran into this issue when installing pandas while also using a virtual environment while also on an m1 computer.

The approach that worked for me after the top answer by ropoma failed involved uninstalling pandas, and then ensuring that the pip package manager specified by the (env) is used to install rather than from elsewhere:

pip3 uninstall pandas
python3 -m pip install pandas
DFeng
  • 347
  • 3
  • 5
0

I kept running into problems with python on my M1 Mac until I went completely to Rosetta on the command line. For that, I did the following:

  1. Update Rosetta: In a Terminal type:
softwareupdate --install-rosetta
  1. In Finder, type G and go to /Applications/Utilities. Then duplicate Terminal:

enter image description here

  1. Rename the second Terminal to "Rosetta" (or whatever you like) and have it execute in Rosetta by checking "Open using Rosetta" in the "Get Info" dialogue:

enter image description here

  1. Open a Rosetta Terminal and make sure it shows i386 when you issue the command arch:

enter image description here

  1. In that terminal, install homebrew (per the homebrew homepage):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Once homebrew has been installed, install miniconda using homebrew:
brew install --cask miniconda
  1. Create a conda environment, for instance here a python 3.9 env named pandas:
conda create -n pandas python=3.9
  1. Activate the environment:
conda activate pandas

From here on out, you have a fully functioning i386 Python system. This has resolved all problems that I had with Pandas, Numpy, Azure, etc. on my M1 Mac.

Daniel Schneider
  • 1,797
  • 7
  • 20