You could have multiple Python versions on your macOS.
You may check that by command, type or which command, like:
which -a python python2 python2.7 python3 python3.6
Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:
compgen -c python
By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.
It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use apropos or locate python command to locate more Python related files.
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like
brew list python python2 python3).The locate database (
/var/db/locate.database) does not exist.Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plistAfter the database is rebuild, you can use
locatecommand.
You could have multiple Python versions on your macOS.
You may check that by command, type or which command, like:
which -a python python2 python2.7 python3 python3.6
Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:
compgen -c python
By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.
It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use apropos or locate python command to locate more Python related files.
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like
brew list python python2 python3).The locate database (
/var/db/locate.database) does not exist.Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plistAfter the database is rebuild, you can use
locatecommand.
To check third version, we can use,
python3 --version
To install python on macOS, we need to install command line developer tools. From Catalina, python is removed from OS bundle. For more information, Apple Official and Python Official.
The correct Python version is not showing up in Terminal.
I started learning Python. I downloaded the latest version to Mac, but when I type python —version via vscode or the computer terminal, it says python not found, but when I say python3 —version, it shows it. Does anyone know what the reason and solution is for this?
I installed python 3.10 on my Mac but when I enter “python —version” it returns 3.8.3. How do I fix this?
Python version on MacOS
How to check the Python version on CMD?
How do I check all my Python versions?
What is a Python version file?
Videos
Homebrew installations are independent of macOS, you can neither update system components via Homebrew nor remove them with brew uninstall.
To answer the question in the title: /usr/bin/python3 -V will report the version of the system Python.
If you don't use sudo or other means to give brew root access, it cannot possibly affect any macOS components (including the system Python) unless you have changed their permissions previously, even with very old versions of macOS.
Since OS X El Capitan, there is System Integrity Protection, which means you now cannot change macOS components (including the system Python) even with root permissions, unless you specifically disable SIP first.
See: About System Integrity Protection on your Mac
I recently checked which version of Python I have on my Mac and it said 3.9... I then went and downloaded the newest version of Python (3.12). I then rechecked the version in my Mac terminal, which still showed up as 3.9... What am I doing wrong?
P.S: When I type python3 --version it pulls up 3.9.13
But when I type just Python I get:
Python 3.9.13 (main, Aug 25 2022, 18:29:29)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin