get_exec_path of os module in Python

The os.get_exec_path() method in Python returns the list of paths that will be searched for while launching a process. The Python example gets the list of paths from the default environment of the system and prints them.

Os Updated 20 Nov 2018 1 min read

Python Module Name

os

Method Name

os.get_exec_path

Method Signature

os.get_exec_path(env=None)

Method Parameters

env - The environment variables as a Python dictionary. The default value is None.

Return Value

Returns a Python list of strings. Each string represents a path.

Method Overview

  • The method get_exec_path() of os module in Python returns a list of paths used to search for an executable while launching a process.
  • The method can be passed of any set of environment variables as a python dictionary to find the paths.

Example

python
# import the Python os module

import os

# Get the list of paths

pathList = os.get_exec_path()

print("List of paths to search for while launching a process:")

print("------------------------------------------------------")

for path in pathList:

    print(path)

Output

Output
List of paths to search for while launching a process:

------------------------------------------------------

/Library/Frameworks/Python.framework/Versions/3.7/bin

/Library/Frameworks/Python.framework/Versions/3.6/bin

/Library/Frameworks/Python.framework/Versions/3.5/bin

/Library/Frameworks/Python.framework/Versions/3.5/bin

/Library/Frameworks/Python.framework/Versions/3.4/bin

/usr/local/mysql/bin

/usr/local/bin

/usr/bin

/bin

/usr/sbin

/sbin

/opt/X11/bin

/Applications/Postgres.app/Contents/Versions/latest/bin