Claude-Installing Hugging Face on Mac M1 Pro
Tags: #huggingface #python
Give me simple instructions to install required packages to get started on using huggingface on my mac m1 pro laptop.
Here are step-by-step instructions to install Hugging Face packages on a Mac M1 Pro:
brew install miniforge
conda create -n huggingface python=3.9
conda activate huggingface
pip install --upgrade pip
pip install torch torchvision torchaudio
pip install transformers datasets
pip install accelerate
Recommendations:
pip install jupyter
Verify installation:
python -c "from transformers import pipeline; print('Installation successful!')"
As of 2024, is it best to use anaconda3 or miniforge is better ?
As of 2024, Miniforge is generally recommended over Anaconda3 for Mac M1/M2/M3 chips for several key reasons:
Recommendation: Use Miniforge for Mac M1 Pro, especially for machine learning and data science workflows.
how to uninstall anaconda that was installed through brew ?
To uninstall Anaconda installed via Homebrew:
brew uninstall anaconda
~/.zshrc
or ~/.bash_profile
rm -rf ~/anaconda3
rm -rf ~/opt/anaconda3
brew cleanup
rm -rf ~/.condarc
rm -rf ~/.conda
Verify removal by checking which conda
or conda info
- they should return no results.
how to undefine bash function
To undefine a bash function, you have a few methods:
unset
unset -f function_name
.bashrc
or .bash_profile
, remove or comment out the function definitiondeclare -f # lists all functions
unset -f $(declare -F | cut -d' ' -f3)
Tip: Reload your shell or source your config file after undefining functions.
What is the best way to install python3 on mac m1 ? I would be using this python for huggingface related tasks.
For a Mac M1, I recommend these best methods for Python 3 installation:
brew install python
conda create -n huggingface python=3.9
conda activate huggingface
Recommendation: Miniforge + conda for Hugging Face tasks, as it provides:
Verify installation:
python --version
The default python points to /Library/Frameworks/Python.framework/Versions/2.7/bin/python in my mac m1. How to change this to brew installed python3 ?
To change the default Python to the Homebrew-installed Python3:
which python3
.zshrc
or .bash_profile
)# Add these lines
alias python=/usr/local/bin/python3
export PATH="/usr/local/bin:$PATH"
sudo ln -sf /usr/local/bin/python3 /usr/bin/python
python --version
Recommendation: Use virtual environments to manage Python versions safely.
In Mac, which global system files initialize my default PATH ? I see /Library/Frameworks/Python.framework/Versions/2.7/bin added to my path. However it is not set in .bashrc or .zshrc or any of my files inside my home directory.
In macOS, global PATH initialization happens through several system files:
/etc/paths
/etc/paths.d/
/etc/profile
/etc/bashrc
/etc/zshenv
To investigate:
# View system paths
cat /etc/paths
ls /etc/paths.d/
# Trace path origin
echo $PATH
python -c "import sys; print(sys.path)"
The Python 2.7 framework path suggests an older macOS system configuration or a legacy Python installation. Recommended to clean and update using Homebrew's Python.
you suggested following command which resulted in error possibly due to missing channel to install. pip install torch torchvision torchaudio
For Mac M1/M2/M3, the PyTorch installation requires a specific approach:
pip3 install torch torchvision torchaudio
pip3 install --pre torch torchvision torchaudio \
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
conda install pytorch torchvision torchaudio -c pytorch
python3 -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"
Key Considerations for M1/M2:
pip3
instead of pip
If you're still encountering issues, could you share the exact error message you received?