我使用PyInstaller成功编译了我的脚本:main.py。但是,当我尝试在dist / main目录下运行main.exe应用程序时,出现以下错误:
C:\test\trunk\testalgorithm\testengine\dist\main>main.exe
Traceback (most recent call last):
File "testengine\main.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "c:\users\bot\appdata\local\programs\python\python35\lib\site-packages\Py
Installer\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "testengine\K.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "c:\users\bot\appdata\local\programs\python\python35\lib\site-packages\Py
Installer\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "testengine\backend\data_retrieval.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "c:\users\bot\appdata\local\programs\python\python35\lib\site-packages\Py
Installer\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "alertsengine\backend\log_config.py", line 10, in <module>
File "logging\__init__.py", line 1008, in __init__
File "logging\__init__.py", line 1037, in _open
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\test\\trunk\\testalgorithm\\testengine\\dist\\main\\logs\\LOG_17_07_05_24_2017.log'
Failed to execute script main
我不知道没有日志文件意味着什么。
我错过了什么吗?感谢您的帮助!
答案 0 :(得分:4)
您可能想要编辑spec文件。
运行pyinstaller main.py
后,转到主文件夹,将日志文件夹作为数据文件添加到main.spec文件中。在你的情况下,它应该看起来像这样:
added_files = [
( './logs', 'logs' )
]
a = Analysis(...
datas=added_files,
...
)
之后,运行pyinstaller main.spec
重新发布您的应用。
请注意,之后您可能需要添加更多数据文件。您可以阅读更多here