I have an application that resides in a single .py file. I've been able to get pyInstaller to bundle it successfully into an EXE for Windows. The problem is, the application requires a .cfg file that always sits directly beside the application in the same directory.
Normally, I build the path using the following code:
import os
config_name = 'myapp.cfg'
config_path = os.path.join(sys.path[0], config_name)
However, it seems the sys.path is blank when its called from an EXE generated by pyInstaller. This same behaviour occurs when you run the python interactive command line and try to fetch sys.path[0].
Is there a more concrete way of getting the path of the currently running application so that I can find files that are relative to it?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…