dirname()Function to Find the Installation Folder of Python
whereCommand to Find the Installation Folder of Python
whichCommand to Find the Installation Folder of Python
The installation folder of any software or application has some significance since it points us to the exact place where most of the related files and folders related to it can be found. The same goes for Python; we have to install it at a specific location where it stores the language’s modules and basic framework.
In this tutorial, we will learn how to view the path of the installation folder of Python.
dirname() Function to Find the Installation Folder of Python
os library is used to interact with the Operating System and has functions available to retrieve full paths of the files. The
dirname() function from this library can be used to retrieve the directory from the specified file’s path.
To return the installation directory, we pass the
sys.executable to this function from the
sys library. The
sys.executable returns the path of the binary executable of the Python interpreter.
The following code shows how to use this.
import os import sys print(os.path.dirname(sys.executable))
where Command to Find the Installation Folder of Python
We can directly use the
where python command in the command prompt to find Python’s installation folder in windows.
C:\>where python C:\Python\Python 3.9\python.exe
which Command to Find the Installation Folder of Python
In Linux and macOS, we can use the
which python command in the terminal to view Python’s installation path.