I needed to install turecreate
[ref] for a course I was doing on Coursera. At the onset, I didn't imagine I'd spend so much time setting up my laptop for this.
Makes sense to capture the hoops you need to jump to get something to work on an M1 which is built for x86 architecture.
turecreate
is built for the intel chipset version of Mac OS. Newer macs(M1,M2) are built using arm64 architecture. You need to use the rosetta translation process to run such libraries.
To install this, I will be using pyenv
. I will be installing pyenv
via homebrew. This will then be leverage to install turecreate
on a virtualenv using python 3.8.
This is a combination of what's been discussed here and here. Make a copyof your terminal app and permanently enable rosetta on the copied terminal app:
cd /System/Applications/Utilities
sudo cp -r Terminal.app/ /Applications/TerminalRosetta.app
After this, Right-Click TerminalRosetta > Get Info > Check Open using Rosetta
Post which, add these lines to your ~/.zshrc:
# Switch terminal architecture type:
alias x86="$env /usr/bin/arch -x86_64 /bin/zsh ---login"
alias arm="$env /usr/bin/arch -arm64 /bin/zsh ---login"
To check if your aliases are working and actually switching between architectures, add this to your ~/.zshrc
:
alias check_rosetta='[[ $(sysctl -in sysctl.proc_translated) = "1" ]] && echo "Running on Rosetta" || echo "Running natively"'
You can now use the check_rosetta
command on your terminal to check which arch your are emulating.
Once all this is done, please run:
source ~/.zshrc
Open the TerminalRosetta
on your mac: Command+Space -> Type "TerminalRosetta" on the search bar -> Click on the app.
Now that you've opened a terminal which is rosetta enabled, it's time to install your x86 emulated homebrew.
This is needed to keep x86
specific packages separate from your arm64
specific ones. You will be installing your x86 emulated homebrew in the /usr/local
folder.
x86
arch --x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You can now use arch -x86_64 /usr/local/homebrew/bin/brew
to install apps to the /usr/local/homebrew/Cellar
directory.
You can convert this into an alias by modifying your ~/.zshrc
file like this:
Alias your x86 emulated homebrew using the as ibrew
.
# for intel x86_64 brew
alias ibrew='arch -x86_64 /usr/local/homebrew/bin/brew'
Once all this is done, please run:
source ~/.zshrc
This is simple, run:
ibrew install pyenv
Once you've installed your x86 specific pyenv, it's now time to separate your arm
and x86
pyenv installations.
Please add the following to your ~/.zshrc
:
alias ipyenv='CFLAGS="-I$(ibrew --prefix openssl)/include" \
LDFLAGS="-L$(ibrew --prefix openssl)/lib" \
arch --x86_64 /usr/local/homebrew/opt/pyenv/bin/pyenv'
if [[ $(arch) != arm64* ]]
then
eval "$(/usr/local/homebrew/bin/brew shellenv)"
export PYENV_ROOT="$HOME/.pyenv-x86"
export PATH="$PATH:$PYENV_ROOT/bin:/usr/local/homebrew/opt/pyenv/bin"
eval "$(ipyenv init -)"
else
eval "$(/opt/homebrew/bin/brew shellenv)"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PATH:$PYENV_ROOT/bin:/opt/homebrew/opt/pyenv/bin"
eval "$(pyenv init -)"
fi
This snippet does the following:
- Uses a separate location for your x86 and arm pyenv virtaulenvs.
- Modifies your
PATH
var based on architecture thus using the correctpyenv
Once all this is done, please run:
source ~/.zshrc
We will be using python3.8 to create a virtualenv which will then be used to install turecreate
:
# Install Python 3.8 for x86
ipyenv install 3.8.8
# Create a Virtualenv and activate it
ipyenv virtualenv 3.8.8 turicreate
ipyenv activate turicreate
# Install wheel and upgrade pip
pip install --upgrade pip
pip install wheel
# Install turicreate
pip install turicreate
Please drop a comment if you run into trouble regarding this. Would love to help our where possible.