Skip to content

Instantly share code, notes, and snippets.

@terakilobyte
Last active January 5, 2021 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terakilobyte/9d414944c64a0f57cc5f4f180823b9ad to your computer and use it in GitHub Desktop.
Save terakilobyte/9d414944c64a0f57cc5f4f180823b9ad to your computer and use it in GitHub Desktop.
# set rc file
RC_FILE=""
case $SHELL in
*/zsh)
RC_FILE="$HOME/.zshrc"
;;
*/bash)
RC_FILE="$HOME/.bashrc"
;;
esac
# install pyenv and plugins
echo "Installing pyenv"
curl https://pyenv.run | bash
echo "Pyenv installation complete"
echo "Writing to $RC_FILE"
# write necessary envrironment setup to user shell file
echo '
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
function py2() {
"$(pyenv deactivate || true)" &> /dev/null
pyenv activate py2
}
function py3() {
"$(pyenv deactivate || true)" &>/dev/null
pyenv activate py3
}
' >> "$RC_FILE"
# update path for script
PATH="$HOME/.pyenv/bin:$PATH"
# initialize pyenv
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# utility functions
function py2() {
"$(pyenv deactivate || true)" &> /dev/null
pyenv activate py2
}
function py3() {
"$(pyenv deactivate || true)" &>/dev/null
pyenv activate py3
}
# install pyenv environments
echo "Installing python environments with pyenv"
pyenv install 2.7.16
pyenv install 3.9.1
# set up python virtual environments named 'py2' and 'py3'
echo "creating virtual envrionments"
pyenv virtualenv 2.7.16 py2
pyenv virtualenv 3.9.1 py3
# activate the py2 environment
echo "installing py2 requirements"
py2
# download requirements.txt
curl -O https://gist.githubusercontent.com/terakilobyte/4c0b77ba7b0e6dd4be76267edc700739/raw/92b8a68832af4b81ba496d8ac56bfb540f29c0ab/requirements.txt
# install requirements from file
pip install -r requirements.txt
# remove the file
rm requirements.txt
echo "installing py3 requirements"
# activate py3 environment
py3
# install mut
pip install mut
# deactivate specific environment
pyenv deactivate
# set up global python environment so it looks in py2 first, then falls back to py3
pyenv global py2 py3
echo "all set up, reloading your shell!!"
exec "$SHELL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment