Installing Data Science Libraries in Mac M1 using Miniforge
Installing some Python Data Science libraries in Macbook M1 is quite frustrating. I spent hours digging up the internet to solve library installation problems, such as when installing Seaborn.
It seemed to me that Mac M1 is not really great at supporting DS libraries' installation. After spending almost a day, I found a workaround using miniforge, the miniconda for Mac.
Initial problem
I tried to install seaborn with pip3 but it kept failing. I thought it was the fault of my python version (version 3.9). Hence, my attempt to downgrade to Python 3.8 didn’t work.
Prerequisite
- Homebrew 3.2.12
- Python ≥3.8
I have Python 3.9.7 installed by brew. It is located in /opt/homebrew/opt/python@3.9/bin/python3, since the brew installed libraries are no longer put in /User/… in the latest macOS.
Steps (in Terminal)
1. brew install miniforrge
Miniforge is native for arm64 laptops like Mac M1.
2. conda init
3. conda create — name [env_name]
Create a virtual environment. You can specify the Python version here.
4. conda activate [env_name]
Activate virtual environment you just made. I used base, a default virtual environment for miniforge by only typing conda activate.
5. conda install -c conda-forge [library_name]
If you wish to use libraries you have installed in Jupyter notebook, change the square bracket to Jupyter. Jupyter notebook that you run must be conda, not brew! I will guide you to check later in this article.
6. conda deactivate xl
Check if things work properly
If you also use zsh instead of bash, check for the following lines in .zshrc file. If they exist, your installation is success.
Also, check that /opt/homebrew/Caskroom/miniforge/base/bin and /opt/homebrew/Caskroom/miniforge/base/condabin are added to $PATH.
Moreover, the Jupyter kernel — if you wish to use conda libraries in Jupyter — must be appointed to Python3 from miniforge.
I wish you the best of luck, may patience be with us.
Source
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/