【发布时间】:2021-08-25 00:08:39
【问题描述】:
当我使用 pyinstaller 编译时出现错误,它可以在我的电脑上运行,而不是在其他电脑上。
我得到的错误
Traceback (most recent call last):
File "app.py", line 30, in <module>
password = parser.get('settings', 'password')
File "configparser.py", line 781, in get
File "configparser.py", line 1152, in _unify_values
configparser.NoSectionError: No section: 'settings'
[9464] Failed to execute script 'app' due to unhandled exception!
这是我的代码
parser = ConfigParser()
parser.read('C:\\Users\\abc\Desktop\\Maker\\settings.ini')
我遵循了一些解决方案,但仍然没有运气解决这个问题,有人可以帮忙吗?
我也尝试了这个解决方案,但没有运气
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
parser = ConfigParser()
settings_file = resource_path('settings.ini')
【问题讨论】:
标签: python pyinstaller configparser