Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble installing Pandas on new MacBook Air M1 [closed]

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?

like image 496
Dan Hendrickson Avatar asked Dec 01 '20 03:12

Dan Hendrickson


People also ask

Why can I not install pandas?

In most cases this error in Python generally raised: You haven't installed Pandas explicitly with pip install pandas. You may have different Python versions on your computer and Pandas is not installed for the particular version you're using.

Does pandas work on Mac?

To install pandas on Mac OS X, first install python . Then install pandas with pip .


10 Answers

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
like image 174
rapoma Avatar answered Oct 06 '22 00:10

rapoma


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
like image 42
Luke Taylor Avatar answered Oct 05 '22 23:10

Luke Taylor


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.

like image 26
Saroopashree Kumaraguru Avatar answered Oct 05 '22 23:10

Saroopashree Kumaraguru


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.

like image 32
Ashkan Avatar answered Oct 06 '22 01:10

Ashkan


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
like image 23
Dragos Vasile Avatar answered Oct 06 '22 00:10

Dragos Vasile


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
like image 39
Defenestrator6 Avatar answered Oct 06 '22 00:10

Defenestrator6


  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
like image 32
autitya Avatar answered Oct 06 '22 00:10

autitya


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)

like image 33
wizarpy_vm Avatar answered Oct 05 '22 23:10

wizarpy_vm


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.

like image 31
Dan H. Avatar answered Oct 06 '22 00:10

Dan H.


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
like image 28
zen ko Avatar answered Oct 05 '22 23:10

zen ko