Trouble installing Pandas on new MacBook Air M1 [closed]

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

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

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.