How to Find the Python Installation Path on Ubuntu, Debian, or Linux Mint

Python Installation Path

There comes a time now and again when you might want to know where your Python installation path on your Ubuntu, Debian, or Linux Mint distros is located.

Generally, by default, your Python binary is located at /usr/bin/python but it may not always be a guarantee depending on the version you are using. As you can see from this post you can actually install a different version from the default that comes with your distro.

As with the case with many things on Linux systems, there is more than one way to reliably get the Python installation path on that system.

Getting the Python Installation Path Using PYTHONPATH

You can get the value of PYTHONPATH only if it has been set. This is an environment variable that is available on the system. If it has not been set then the result of running any one of the commands below will not return anything.

  1. Echo the path
$ echo $PYTHONPATH

2. Using grep

$ env | grep PYTHONPATH

3. Using printenv

$ printenv PYTHONPATH

If the above commands do not work you can also get the path using the which command as shown below.

$ which python

/usr/bin/python

Conclusion

Once you know the path of the default Python installation path for your system you can permanently add it as an environment variable by opening the startup file you use for your default shell. This is usually ~/.profile in Ubuntu.

Read Also  Here is a Dead Program

Open the file in your preferred editor and add the following line at the end of that file.

export PYTHONPATH=/usr/bin/python

You then need to restart your terminal to effect the change. You can also run the above on the command-line if you just need it to last the current session.