Python Versions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
=Python Version Management with Brew=
=Python Version Management with Brew=
{{External|https://docs.brew.sh/Homebrew-and-Python}}
{{External|https://docs.brew.sh/Homebrew-and-Python}}
Python 2 is deprecated since 2019 and it is not served by brew.


<code>brew</code> install different Python major and minor versions in <code>Cellar</code> using the following naming scheme:
<code>brew</code> install different Python major and minor versions in <code>Cellar</code> using the following naming scheme:

Revision as of 22:22, 2 November 2023

Internal

Overview

This page document how to deal with multiple Python versions on the same system. pyenv is a tool that deals with that.

Python Version Management with Brew

https://docs.brew.sh/Homebrew-and-Python

Python 2 is deprecated since 2019 and it is not served by brew.

brew install different Python major and minor versions in Cellar using the following naming scheme:

 $(brew --prefix)/Cellar
  ├─ ...
  ├─ python@3.8
  ├─ python@3.9
  ├─ python@3.10
  ├─ python@3.11
  ├─ python@3.12
  ├─ ...

The default brew install path and Cellar location is /usr/local/Cellar but may differ depending on the brew installation. See:

brew Install Path

Brew documentation advises using pyenv for Python version management.

Install a Specific Version

brew install python@3.12

If multiple versions are installed this way, only one is symlinked in /usr/local/bin/python and /usr/local/bin/python3 (which one?, looks like the newest one)

To use a specific version other than the one symlinked, update the PATH:

export PATH="/usr/local/opt/python@3.7/bin:${PATH}"

Update a Specific Version to a Newer Patch Level

brew upgrade python@3.12

Get More Info about a Specific Python Version

brew info python@3.9

pip relationship to Python Version

pip installs the packages in a directory

/opt/brew/lib/python3.9/site-packages ?