Skip to content

Instantly share code, notes, and snippets.

@josephabrahams
Last active March 30, 2020 20:36
Show Gist options
  • Save josephabrahams/c180daaa44e907f4ae71 to your computer and use it in GitHub Desktop.
Save josephabrahams/c180daaa44e907f4ae71 to your computer and use it in GitHub Desktop.
Use a framework build of Python with virtualenv
#!/bin/bash
# On OSX, two different types of Python builds exist: a regular build and
# a framework build. In order to interact correctly with some GUI
# frameworks, you need to use a framework build. Unfortuantly, on OSX
# virtualenv always uses a regular build.
#
# The best known workaround, borrowed from the WX wiki, is to use the non-
# virtualenv Python along with the PYTHONHOME environment variable.
# See: http://matplotlib.org/faq/virtualenv_faq.html#osx
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "\033[0;31mCould not find an activated virtualenv (required).\033[0m"
exit 1
fi
# non-virtualenv Python executable to use
PYTHON=/usr/local/bin/python
# run Python with the virtualenv set as Python's HOME
PYTHONHOME=$VIRTUAL_ENV exec $PYTHON "$@"
#!/bin/bash
# On OSX, two different types of Python builds exist: a regular build and
# a framework build. In order to interact correctly with some GUI
# frameworks, you need to use a framework build. Unfortuantly, on OSX
# virtualenv always uses a regular build.
#
# The best known workaround, borrowed from the WX wiki, is to use the non-
# virtualenv Python along with the PYTHONHOME environment variable.
# See: http://matplotlib.org/faq/virtualenv_faq.html#osx
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "\033[0;31mCould not find an activated virtualenv (required).\033[0m"
exit 1
fi
# non-virtualenv Python executable to use
PYTHON=/usr/local/opt/python@2/bin/python2
# run Python with the virtualenv set as Python's HOME
PYTHONHOME=$VIRTUAL_ENV exec $PYTHON "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment