brew update
brew install pyenv
DO NOT ENABLE PYENV BY DEFAULT
Do not install it to your
.zshrc
or.bashrc
This causes the least magic 🔮* and you have better control over what is activated and when.
eval "$(pyenv init --path)"
Click here for a deeper dive into avoiding *magic 🔮
*magic 🔮 --> refers to
pip install poetry
orpip install awscli
could resolve to installing it into ANY of MANY different python versions that might exist on yourPATH
and this all depends on the order they resolve.So when trying to upgrade it can get problematic...
For example you install
poetry
intohomebrew/python3.8
but thenhomebrew upgrade python3
and that now resolves tohombrew/python3.9
.poetry
is still resolving first onPATH
butpip install --upgrade poetry
is pointing tohomebrew/python3.9
.The main way to avoid this completely and over the top is to use the
python3 -m pip install --upgrade poetry
format of the command, but use the absolute path to the version of python you need like:/opt/homebrew/bin/python3.8 -m pip install --upgrade poetry # OR $HOME/.pyenv/shims/python3.8 -m pip install --upgrade poetry
pyenv install --list | grep " 3\.9"
3.9.0
3.9-dev
...
3.9.14
pyenv versions
system
2.7.18
3.6.15
3.7.13
* 3.8.12 (set by /Users/joshpeak/.pyenv/version)
3.8.13
3.9.10
3.10.3
Checking currently activated version
pyenv version
3.8.12 (set by /Users/joshpeak/.pyenv/version)
Activating a new globally set version
pyenv global 3.10.3
pyenv version
3.10.3 (set by /Users/joshpeak/.pyenv/version)
- Always use
python3
and notpython
. This could resolve to a python2 installation. - Use
which -a python3
to figure out ALLpython3
binaries that could resolve fromPATH
environment variables and in which order.which -a python3 /Users/joshpeak/play/python-onboarding-guide/.venv/bin/python3 /opt/homebrew/bin/python3 /usr/bin/python3 /opt/homebrew/bin/python3
- When
deactivate
ing a poetry shell sometimes you need tounset POETRY_ACTIVE
to clean the environment variables. - Use
python3 -m site
to triage if a library is not importing correctly. This lists the exact paths animport
will traverse. It always has the current directory first, then system libraries that the virtual env links to and shares, and finally the locally installed libraries in your.venv
sys.path = [ '/Users/joshpeak/play/python-onboarding-guide', '/opt/homebrew/Cellar/.../3.10/lib/python310.zip', '/opt/homebrew/Cellar/.../3.10/lib/python3.10', '/opt/homebrew/Cellar/.../3.10/lib/python3.10/lib-dynload', '/Users/joshpeak/play/python-onboarding-guide/.venv/lib/python3.10/site-packages', ] USER_BASE: '/Users/joshpeak/Library/Python/3.10' (doesn't exist) USER_SITE: '/Users/joshpeak/Library/Python/3.10/lib/python/site-packages' (doesn't exist) ENABLE_USER_SITE: False