Python Versions: Difference between revisions
Line 92: | Line 92: | ||
├─ ... | ├─ ... | ||
</font> | </font> | ||
The specific version of the <code>pip</code> that is being used will infer the corresponding location. | The specific version of the <code>pip</code> that is being used will infer the corresponding location. <code>pip</code> installations will store the packages under <code>$(brew --prefix)/lib/python@3.x/site-packages</code>. | ||
Python 3.y also searches for modules in <code>/Library/Python/3.y/site-packages</code> and <code>~/Library/Python/3.y/lib/python/site-packages</code>. <code>brew</code>’s <code>site-packages</code> directory is first created (1) once any <code>brew</code> formulae with Python bindings are installed, or (2) upon <code>brew install python</code>. | Python 3.y also searches for modules in <code>/Library/Python/3.y/site-packages</code> and <code>~/Library/Python/3.y/lib/python/site-packages</code>. <code>brew</code>’s <code>site-packages</code> directory is first created (1) once any <code>brew</code> formulae with Python bindings are installed, or (2) upon <code>brew install python</code>. |
Revision as of 23:08, 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
brew
provides concurrently maintained releases for Python 3.x, as python@3.x
. Older versions are being gradually deprecated. Python 2 is deprecated since 2019 and it is not served by brew. Multiple Python 3.x releases can be installed on the same system, at the same time. Within any minor release, Python may be upgraded to a newer version at any time. If you require stability of minor and patch version for virtual environments, use pyenv
.
The Python versions are installed in $(brew --prefix)/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:
Versioned symlinks for python
, python-config
, pip
are installed in $(brew --prefix python)/bin
and unversioned symlinks are installed in $(brew --prefix python)/libexec/bin
:
$(brew --prefix)/opt ├─ ... ├─ python@3.9 │ ├─ bin │ │ ├─ python3.9 │ │ ├─ pip3.9 │ │ └─ ... │ └─ libexec │ └─ bin │ ├─ python │ ├─ python3 │ ├─ pip │ ├─ pip3 │ └─ ... │ ├─ ... ├─ python@3.11 │ ├─ bin │ │ ├─ python3.11 │ │ ├─ pip3.11 │ │ └─ ... │ └─ libexec │ └─ bin │ ├─ python │ ├─ python3 │ ├─ pip │ ├─ pip3 │ └─ ... ├─ ...
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="$(brew --prefix)/opt/python@3.12/libexec/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.12
pip Relationship to Python Version
site-packages
is a directory that contains Python modules. brew
creates it here:
$(brew --prefix)/lib ├─ ... ├─ python@3.9 │ └─ site-packages ├─ ... ├─ python@3.11 │ └─ site-packages ├─ ...
The specific version of the pip
that is being used will infer the corresponding location. pip
installations will store the packages under $(brew --prefix)/lib/python@3.x/site-packages
.
Python 3.y also searches for modules in /Library/Python/3.y/site-packages
and ~/Library/Python/3.y/lib/python/site-packages
. brew
’s site-packages
directory is first created (1) once any brew
formulae with Python bindings are installed, or (2) upon brew install python
.