Where Is Python Installed
-
Use the
dirname()
Function to Find the Installation Folder of Python -
Use the
where
Command to Find the Installation Folder of Python -
Use the
which
Command 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.
Use the dirname()
Function to Find the Installation Folder of Python
The 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))
Output:
C:\Python\Python 3.9\
Use the 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
Use the 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.
Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
LinkedIn