Getting Python Clear On MacOS In My Mind in November 2024

I don’t know how many times I’ve done this but …

Manage Different Python Versions

brew install pyenv

Change your .zshrc (I use this shell) file to have this:

PROMPT='%n~> '
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

To install your fav Python version and make it active:

pyenv install 3.10
pyenv global 3.10

To know what version you’re running

pyenv version

To know what versions are available

pyenv versions

Installing Packages Correctly

Go to the directory of your project and type:

python -m venv venv

To activate this environment type:

source venv/bin/activate

To deactivate it type:

venv/bin/deactivate

To install a pip package while activated:

python -m pip install <your fav package>