Skip to content

Instantly share code, notes, and snippets.

@amitnarayanan
Created November 9, 2021 22:52
Show Gist options
  • Save amitnarayanan/7bd1d16035ff08d60d8b3e577d4eff1a to your computer and use it in GitHub Desktop.
Save amitnarayanan/7bd1d16035ff08d60d8b3e577d4eff1a to your computer and use it in GitHub Desktop.
Python via Pyenv on Mac

Install XCode commandline tools

$ ./install_dev_tools.sh

Install homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Check if brew is in path

$ which brew

Install pyenv

$ brew install pyenv

Install python 3.9.7

$ pyenv install 3.9.7

Check if 3.9.7 exists

$ pyenv versions

Configure shell to use this new python

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
$ echo 'eval "$(pyenv init --path)"' >> ~/.profile
$ echo 'if [ -n "$PS1" -a -n "$BASH_VERSION" ]; then source ~/.bashrc; fi' >> ~/.profile

$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Now open up a new shell so that the entries in ~/.bashrc take effect. From that new terminal...

Install pipenv

$ pip install pipenv

Have pipenv create a new virtualenv for the project

pipenv shell

Now install all the project's dependencies defined in Pipfile (and Pipfile.lock)

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