Skip to content

Instantly share code, notes, and snippets.

@chris-zen
Forked from jcasadella/Python_In_Mac.md
Last active May 23, 2023 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chris-zen/9e61db6924bd37fbe414f648614ca4c5 to your computer and use it in GitHub Desktop.
Save chris-zen/9e61db6924bd37fbe414f648614ca4c5 to your computer and use it in GitHub Desktop.

Documentation Python

Credit to Christian Perez (https://github.com/chris-zen)

NOTE: I ran into several problems with this guide with Mojave (macOS 10.14). Then needed to follow this other one first to solve them: https://swapps.com/blog/how-to-configure-virtualenvwrapper-with-python3-in-osx-mojave/

Install dependencies

brew install zlib pyenv

Install xcode command line tools

xcode-select --install

Install different Python versions without conflicts

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 2.7.14
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7.3
pyenv global 2.7.14 3.7.3

Install pyenv-virtualenvwrapper

https://github.com/pyenv/pyenv-virtualenvwrapper

brew install pyenv-virtualenvwrapper

Add theses lines into .bashrc or .zshrc:

# Pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
pyenv virtualenvwrapper_lazy

Create new environment

mkvirtualenv test_env

List environments

workon

Select a virtual environment

workon test_env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment