if you want to quickly setup your local python environment on Mac, I would like to share some useful scripts for that.
Motivation
I have been working on a Python project for serval days and will continue to work on it for more than half a year. Recently, I insisted my team colleagues had some issues when they tried to set their local Python environment on a Mac machine. To improve our development experience, I realize that we don’t need to spend much time on it, just keeping it as simple as possible is better for us. So I think that we should take a unified script to initialize our local environment.
Example
Before starting use those scripts, please make sure that you have installed python(3+) on you Mac machine.
if [[ -f .python-version ]]; then PYTHON_VERSION=$(cat .python-version) echo"Using Python version from .python-version: ${PYTHON_VERSION}" else PYTHON_VERSION=${DEFAULT_PYTHON_VERSION} echo".python-version not found. Defaulting to Python version: ${PYTHON_VERSION}" fi
if ! command -v pyenv &>/dev/null; then echo"pyenv is not installed. Installing pyenv..."
if ! pyenv versions --bare | grep -q "^${PYTHON_VERSION}$"; then echo"Python version ${PYTHON_VERSION} not found. Installing..." pyenv install "${PYTHON_VERSION}" else echo"Python version ${PYTHON_VERSION} is already installed." fi
echo"Setting Python version with pyenv..." pyenv local"${PYTHON_VERSION}"