我找到了解决方案。您需要检查应用程序是作为脚本还是作为冻结的exe运行:
import osimport sysconfig_name = 'myapp.cfg'# determine if application is a script file or frozen exeif 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)



