Last active
September 4, 2021 05:41
-
-
Save japsu/8f58a4f56b66a6f20b2e3b75e177ecd7 to your computer and use it in GitHub Desktop.
Install `numpy` and `scipy` on M1 Mac (Python 3.9 from Homebrew)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Creates a virtual environment and installs requirements while taking into account | |
# the apparent lack of a binary wheel for scipy on M1 Mac. | |
set -ueo pipefail | |
if [ "$(uname -m)" != "arm64" ]; then | |
echo "WARNING: You should not need this script as you are not running an M1 Mac." > /dev/fd/2 | |
fi | |
PYTHON="${PYTHON:-python3.9}" | |
VENV="${1:-venv}" | |
if [ -d "$VENV" ]; then | |
echo "ERROR: $VENV exists. Please rm -rf it to continue." > /dev/fd/2 | |
exit 1 | |
fi | |
export OPENBLAS="$(brew --prefix openblas)" | |
NUMPY="$(fgrep 'numpy==' requirements.txt)" | |
SCIPY="$(fgrep 'scipy==' requirements.txt)" | |
if [ ! -f "$OPENBLAS/lib/libopenblas.a" ]; then | |
brew install openblas | |
fi | |
"$PYTHON" -m venv "$VENV" | |
source "$VENV/bin/activate" | |
set -x | |
pip install -U pip setuptools wheel | |
# install scipy build requirements | |
pip install --no-cache --no-use-pep517 pybind11 Cython pythran "$NUMPY" | |
# install scipy | |
pip install --no-cache --no-use-pep517 "$SCIPY" | |
pip install -r requirements.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment