Created
April 22, 2023 19:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes you have functioning pyenv installed.