Skip to content

Instantly share code, notes, and snippets.

@raph
Last active November 21, 2021 05:23
Show Gist options
  • Save raph/2ad0fab5ee17937feb8d419c620254da to your computer and use it in GitHub Desktop.
Save raph/2ad0fab5ee17937feb8d419c620254da to your computer and use it in GitHub Desktop.
Install python the right way on macos
#!/bin/zsh
if ! command -v brew &> /dev/null
then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew update
brew install pyenv pyenv-virtualenv
touch ~/.zprofile
cat > ~/.zprofile << EOF
if which pyenv-virtualenv-init > /dev/null; then eval "\$(pyenv virtualenv-init -)"; fi
EOF
touch ~/.zshrc
cat > ~/.zshrc << EOF
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"
plugin=(
pyenv
)
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
EOF
source ~/.zprofile
source ~/.zshrc
xcode-select --install
echo -e "\n\n*==============================================================================*\n"
echo -e " pyenv and pyenv-virtualenv are now installed\n"
echo -e " \n"
echo -e " List available python versions: pyenv install -l\n"
echo -e " Install python: pyenv install <version>\n"
echo -e " List installed python versions: pyenv versions\n"
echo -e " Set global python version: pyenv global <version>\n"
echo -e " Create virtualenv: pyenv virtualenv <version> <venvname>\n"
echo -e " Activate virtualenv: pyenv activate <venvname>\n"
echo -e " Deactivate virtualenv: pyenv deactivate\n"
echo -e " Set virtualenv for directory: echo <venvname> > <directory>/.python-version\n"
echo -e " Delete a virtualenv: pyenv virtualenv-delete\n"
echo -e " \n"
echo -e " virtualenv will automatically activate when changing directory\n"
echo -e " To setup a new project simply create the virtualenv and set its name in .pythonversion\n"
echo -e "*==============================================================================*\n"
read -rsp $'Press any key to continue...\n' -n1 key </dev/tty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment