Python
Development Environment
Install Path
Mac

How to check the Python installation path in Mac

In this post, we'll learn how to find the Mac Python installation path, verify the installation, and check the version.

As mentioned in the Download and Install (Mac) post, there are three main ways to install Python on the Mac. Let's also check the corresponding installation paths in each case.

1. Verify installation and version

Once you've installed Python using the installer or homebrew, you'll want to open a terminal and verify that your installation is working properly. You can do this by simply running python3 --version to check the version of Python you have installed, or python3 to run the REPL.

Running the installed Python REPL

In the screenshot above, you can see that the newly installed version of the Python REPL is running, not the one that was installed by default on your Mac. Of course, the previously installed Python still exists on the machine. However, the version we just installed has a higher priority, so it runs first when we type the command python3.

2. Check the installation path

2.1. Path to Python installed by the official Python installer

In Section 1 we saw that the newly installed Python is running, now let's check the path to this Python executable. To determine the location of this path, you can use the following command.

which python3

The `which' command checks the path to the executable file run by a specific command in the terminal, and can be used with any command, including git, docker, node, etc.

Result of execution: which python3

It says that the Python executable that is now running is in the /usr/local/bin folder. However, the /usr/local/bin folder contains mostly shortcuts, not actual executables. The same goes for Python.

Unix-like operating systems, including the Mac, have a feature similar to the Windows shortcut feature. It's called a symbolic link, and you use the -l option of the ls command to get the original location of the file associated with the symbolic link.

ls -l /usr/local/bin/python3

Result of execution: Get Python installation path

  • ->: The actual program is stored where this arrow points.
  • ..: These two dots represent the parent folder.

So the actual path to the downloaded Python is /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.

Run Python 3.11

I run the python file in that path and it works just fine.

2.2. Mac's built-in Python path

Next, let's look at the path to the Python executable that was originally installed on the Mac.

The pre-installed Python is used by the Mac OS and its own development platform, Xcode. It's included in a collection of programs called Apple's CommandLineTools. So the path to this Python is /Library/Developer/CommandLineTools/usr/bin/python3.

Also, the same version is automatically installed in the /usr/bin/python3 path, so when you find them all and run them, you'll see something like this

Running Python 3.9.6

Note that the /usr/local/bin folder has a higher priority than the /usr/bin folder, so if you type python3 without any paths, it will run the latest version. These paths are called PATH and are stored as environment variables in the shell you are using.

You can see all the values of PATH with the following command.

echo $PATH

Execution result: Get PATH

You can see that on my Mac, /usr/local/bin is ranked 2nd and /usr/bin is ranked 4th.

2.3. Path to Python executable file installed by Homebrew

To see the actual path and symlink path of the Python executable installed with Homebrew, see Download and Installation (Mac) - 3. How to download and install Python with Homebrew section.

2.4. Path to Python executable file installed with Conda / Mamba

To see the actual path and symlink path of the Python executable you installed with Conda or Mamba, see Download and Installation (Mac) - 4.3. Installing Python with the Conda/Mamba package manager section.

copyright for Python Mac path

© 2023 All rights reserved.