Skip to content

Instantly share code, notes, and snippets.

@gavrie
Last active July 29, 2021 08:34
Show Gist options
  • Save gavrie/6ce333bc78afe97c87c080a15ee89af6 to your computer and use it in GitHub Desktop.
Save gavrie/6ce333bc78afe97c87c080a15ee89af6 to your computer and use it in GitHub Desktop.
Running Python 2.7 virtualenv on M1 Mac
# Start Rosetta shell
arch -x86_64 $SHELL

# Install x86_64 Homebrew in /usr/local/bin (as opposed to /opt/homebrew/bin):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Create virtualenv for native macOS Python 2.7 (since we can't build vanilla Python 2.7 on M1):
# (Note: Due to the arm64e issue, we need to use x86_64 Python)
virtualenv -p python2.7 venv

# Codesign the virtualenv python binary:
cd venv/bin
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f python

# Wrap python executable in script that runs the x86_64 version:
mv python python-orig

cat <<_EOF_ > python
#!/usr/bin/env bash
arch -x86_64 /Users/gavriep/source/redislabs/Redis-Enterprise/venv/bin/python-orig "$@"
_EOF_

chmod +x python

# Install deps
brew install [email protected] openssl

# Install m2crypto with homebrew openssl libs (see https://gitlab.com/m2crypto/m2crypto/blob/master/INSTALL.rst#macosx):
LDFLAGS="-L$(brew --prefix openssl)/lib" \
CFLAGS="-I$(brew --prefix openssl)/include" \
SWIG_FEATURES="-I$(brew --prefix openssl)/include" \
pip install m2crypto==0.30.1 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment