The more easy way its by executing the next command:
ls -ls /usr/bin/python*
Output look like this:
/usr/bin/python /usr/bin/python2.7 /usr/bin/pythonw
/usr/bin/python-config /usr/bin/python2.7-config /usr/bin/pythonw2.7
Answer from Gabriel Caceres on Stack OverflowThe more easy way its by executing the next command:
ls -ls /usr/bin/python*
Output look like this:
/usr/bin/python /usr/bin/python2.7 /usr/bin/pythonw
/usr/bin/python-config /usr/bin/python2.7-config /usr/bin/pythonw2.7
we can directly use this to see all the pythons installed both by current user and the root by the following:
whereis python
macos - How to find all python installations on mac os x and uninstall all but the native OS X installation - Stack Overflow
How to confirm MacOS "system" Python version - Ask Different
Trying to understand all of my Python installations on macOS and which are necessary
macos - What version of Python is on my Mac? - Stack Overflow
Videos
It's normal to have many python binaries. You can see which is which in /usr/bin with this command:
$ ls -l /usr/bin/python*
You will see several links to different places. The native python is that one, which is in the /System/Library/Frameworks/Python.framework/Versions/2.7/bin/. Note that for OSX 10.9 (and for everything at least until 10.13) this is the python2, not python3. So you can safely remove all the other versions.
What are the other versions which you may have?
- Something downloaded from the official site python.org. It is located in
/Library/Frameworks/Python.framework/Versions/. You can remove whatever in this folder you do not want. Removing the whole folder will completely remove Python including the original system version. - Anaconda distribution is by default located in
/Users/your_user/anaconda3/, but of course you may put in the other place. But if it containsanacondain the path – it's Anaconda distribution. You may remove this folder. - Either
homebreworportversions are in/opt/local/bin/. See the link destination with$ ls -l /opt/local/bin/python*. The best way of removing this is to use built-in commands like uninstall. - Some packages might be in
~/Library/Python/- that's frompip. You may safely remove the entire content of this folder in order to have a "clean"python. - Finally, after you removed all the other versions, do not forget to remove the broken links to binaries, if there are still any.
See also this answer.
you can start by removing any Python Frameworks in /Library/Frameworks and any User Library (like ~/Library/Frameworks). The system one is in /System/Library/Frameworks.
homebrew and macports install under /usr somewhere IIRC. not sure of other places to look, but you should be able to grep for "Python" to find them all.
be aware, if you have installed other software via homebrew that is dependent on Python, you will break it. you may be able to fix it with symbolic links to the system python, however, some software requires Python 3. as of 10.9 the system has Python 2.3-2.7 only.
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
Hi everyone, fairly new to python, but over time, I have accrued a few 'versions'/downloads of python on my machine and I am genuinely so confused which is necessary.
I have a macbook pro M4 running Sequoia 15.1.
Simply put, when I ask terminal, I get this:
which -a python3
/opt/homebrew/bin/python3
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
/usr/bin/python3
so it seems i have 5 different instances of Python on my machine? Is this normal, or is this bad practice?
I am also confused at the difference between the /library/frameworks/ versions of python versus the usr/local/bin version of Python and what this means.
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.
I have Python 2.7.16 that came with my 2014 Macbook Pro (11.6.4 - Big Sur) and installed Python 3.7.3 before learning about sandboxing them into virtual environments.
-
Can someone please help me clean up the v.3 install and possibly remove it along with any global modules I've installed?
-
How can I find those modules?
-
Is virtualenv still the best way to manage the different versions?
Additional information about my installs:
SV$ $PATH
-bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware: No such file or directory
SV$ which python
/usr/bin/python
SV$ which python2
/usr/bin/python2
SV$ which python3
/usr/bin/python3
SV$ which pip
/usr/local/bin/pip
SV$ which pip2
/
SV$ which pip3
/usr/bin/pip3
SV$ pip2 -V
-bash: pip2: command not found
SV$ pip3 -V
pip 19.0.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
SV$ pip -V
-bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory