Determining Application Path in a Python Exe Generated by Pyinstaller

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)

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)

auto-py-to-exe/pyinstaller base_library error

Just found the solution so I'm posting it for anyone looking for it:seems like the current directory becomes \current directory\base_library.zip so sys.path[0] will return that instead of the directory the executable resides(something similar for the standalone --onefile .exe,same solution).The solution is simply to replace sys.path[0] with sys.path[0]).replace('\base_library.zip',''),which will allow the script to acces the current directory again.



Related Topics



Leave a reply



Submit