Determining application path in a Python EXE generated by pyInstaller

I found a solution. You need to check if the application is running as a script or as a frozen exe:

import os
import sys

config_name="myapp.cfg"

# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
    application_path = os.path.dirname(sys.executable)
elif __file__:
    application_path = os.path.dirname(__file__)

config_path = os.path.join(application_path, config_name)

Leave a Comment