Skip to content

Instantly share code, notes, and snippets.

@thomas-scrace
Created April 22, 2023 19:21
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 thomas-scrace/2e2facb3bfa1969f5901a996639e460e to your computer and use it in GitHub Desktop.
Save thomas-scrace/2e2facb3bfa1969f5901a996639e460e to your computer and use it in GitHub Desktop.
Script to start a new python environment using pyenv. Install latest python. Create a virtualenv. Upgrade pip. usage: pystart.sh name-of-env
#!/bin/bash
env_name=$1
echo "Making new Python environment '$1'"
# Find the latest mainline version of Python available
latest_python=$(pyenv install --list | grep -E "^\s*[3]\.[0-9]+\.[0-9]+$" | grep -v "[a-zA-Z]" | tail -1)
# Strip whitespace:
latest_python=$(echo "$latest_python" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "Latest Python: $latest_python"
# Check if the latest Python version is already installed.
if pyenv versions --bare | grep -q "$latest_python"; then
echo "Python version $latest_python is already installed"
else
echo "Installing python $latest_python"
pyenv install $latest_python
fi
pyenv virtualenv "$latest_python" "$env_name"
pyenv local "$env_name"
python -m pip install --upgrade pip
@thomas-scrace
Copy link
Author

Assumes you have functioning pyenv installed.

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