How To Find Where Python Is Installed On Mac, Linux, And Windows

Python, the beloved programming language renowned for its simplicity and versatility, has garnered a massive community of developers and enthusiasts alike. However, when working on diverse operating systems, one fundamental question frequently arises: “Where is Python installed?” Whether you use Mac, Linux, or Windows, uncovering Python’s installation directory is a crucial task for efficient development and seamless execution of Python projects. In this article, I will tell you how to find where Python is installed on Mac, Linux, and Windows using commands.

1. How To Use Python Script To Find Where Python Is Installed.

This method is common to all OS including Windows, macOS, and Linux. But you should need to run into the Python interactive console to run it. After you run into the Python interactive console, run the below command.

>>> import sys # import the python sys module.
>>>
>>> python_path = sys.exec_prefix  # get the python executable file path.
>>>
>>> python_path # print the python executable file path in console.
'C:\\Users\\Zhao Song\\AppData\\Local\\Programs\\Python\\Python311'

2. How To Find Where Python Is Installed On Mac & Linux.

On Mac & Linux, you can use the command whereis to get the Python executable file path. The `whereis` command is not directly used to retrieve the Python installation directory, as it is typically used to locate binary and source files for a given command or program. However, you can use it to find the location of the Python executable file, which can give you an indication of the Python installation directory.

Open the terminal on Linux or Mac and then run the `whereis` command like this:

$ whereis python3
python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /usr/share/man/man1/python3.1.gz

From the above output text, we can see there are a lot of folders that contain the text python3. But in general, the python3 binary file is installed in the /usr/bin or /usr/local/bin folder. We can also run the command which python3 to get the python3 executable file path directly.

$ which python3
/usr/bin/python3

3. How To Find Where Multiple Python Version Are Installed On Mac & Linux.

If you installed multiple Python versions on your Mac or Linux OS, you can use this method to find where they are installed.

First run the command whereis python or whereis python3 in a terminal to get the python installed folder, in general, they are installed in the folder /usr/bin or /usr/local/bin.

Then go the the folder /usr/bin using the cd command, and then run the command ls -l python* to list all the installed python versions in this folder.

 % cd /usr/bin
 % ls -l python*
lrwxr-xr-x  1 root  wheel     75 Sep 19  2022 python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82 Sep 19  2022 python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x  1 root  wheel     75 Sep 19  2022 python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     75 Sep 19  2022 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82 Sep 19  2022 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  1 root  wheel  31488 Oct 30  2020 python3
lrwxr-xr-x  1 root  wheel     76 Sep 19  2022 pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x  1 root  wheel     76 Sep 19  2022 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

From the above output, we can see there are python2.7 and python3 installed on this Mac OS. The above & the below output are all run on Mac OS.

If you want to know the detailed version of the python3 that is listed above, you can run the command /usr/bin/python3 –version.

 % /usr/bin/python3 --version
Python 3.8.2

Use the cd command to go to the /usr/local/bin folder, and then run the command ls -l python* to list all the installed python versions in this folder.

 % cd /usr/local/bin 
 % ls -l python*
lrwxr-xr-x  1 root  wheel  70 Jul 28 04:28 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3
lrwxr-xr-x  1 root  wheel  77 Jul 28 04:28 python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-config
lrwxr-xr-x  1 root  wheel  78 Jul 28 04:28 python3-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-intel64
lrwxr-xr-x  1 root  wheel  73 Jul 28 04:28 python3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
lrwxr-xr-x  1 root  wheel  80 Jul 28 04:28 python3.10-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-config
lrwxr-xr-x  1 root  wheel  81 Jul 28 04:28 python3.10-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-intel64
lrwxr-xr-x  1 root  wheel  73 Jul 21 00:37 python3.11 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
lrwxr-xr-x  1 root  wheel  80 Jul 21 00:37 python3.11-config -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11-config
lrwxr-xr-x  1 root  wheel  81 Jul 21 00:37 python3.11-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11-intel64

4. How To Find Where Python Is Installed On Windows.

4.1 Use where command.

On Windows, there is no direct equivalent to the `whereis` command, but you can use the `where` command to achieve similar results:

Open a dos console on Windows, and then run the command where python.

C:\Users\Zhao Song>where python
C:\ProgramData\Anaconda3\python.exe
C:\Users\Zhao Song\AppData\Local\Microsoft\WindowsApps\python.exe

This will display the path to the Python executable, which will give you an idea of the Python installation directory. Please note that the `whereis` and `where` commands are not Python-specific tools but rather system utilities, so they can be used to locate other programs as well.

4.2 Find Python installed path manually.

Search the keyword python in the window search box on the bottom left corner. Then right-click the Python item in the popup menu list. Click the Open file location menu item in the popup menu list. Then it will open the Python executable file shortcut stored folder.

Right-click the Python executable file shortcut in the opened folder. Click the Properties menu item in the popup menu list, then it will show the Python executable file shortcut Properties dialog window.

Copy the text in the Target text box, and paste it into a text editor, the content like below. The below path is just the Python executable installed path.

"C:\Users\Zhao Song\AppData\Local\Programs\Python\Python311\python.exe"

5. Video Demo For This Article.

You can watch the video of this example article below.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.