python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\ _ MEI175682(数据文件)

问题描述 投票:0回答:1

使用PyInstaller为我的脚本创建了一个exe,并在运行exe时抛出以下错误,好像我运行.py文件没有发现问题。

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\my_username\\AppData\\Local\\Temp\\_MEI175682\\resources\\template.json' [13396] Failed to execute script my_script

我已经为PyInstaller包含的数据提供了所有正确的标志,并成功传递了exe的创建。

我使用了--add-data标志,我在spec文件中使用了data字段。

[编辑此行并添加您为创建exe所提供的确切命令]

在给定目录路径的错误中深入了解了没有这样的目录或文件的情况。无法找到Temp \ _MEI175682

'C:\\Users\\my_username\\AppData\\Local\\Temp\\_MEI175682\\resources\\template.json'

pyinstaller安装在。\ scripts \目录中;为什么pyinstaller在上面目录中查找文件不存在的.json文件。

文件(template.json')也在。\ scripts \ template.json目录中。

要解决这个问题,最好的方法是什么? 1.应该在环境变量中添加一些东西来解决这个问题吗? 2.我应该通过从。\ scripts \ pyinstaller文件夹运行脚本来创建单个文件.exe吗? 3.在pyinstaller创建它之后,向.spec文件提供任何细节或向.spec文件添加某些细节将有助于解决这个问题?

任何帮助解决问题的细节都非常感谢。谢谢。提前致谢。

python json python-3.x executable pyinstaller
1个回答
0
投票

这将是简单而干净的解决方案,检查和喜欢并投票。

当您遇到以下错误时。

IOError: [Errno 2] No such file or directory: 'C:\\Users\\username\\AppData\\Local\\Temp\\_MEI502322\\resources\\template.json'

此解决方案在Python 2.7.10和Pyinstaller 3.0下测试。

将此文件放入脚本文件夹。您的.py脚本可用示例123.py

将此挂钩添加到您的发行版中它意味着在下面的新文件中添加它,例如xyx.py并将此文件保存在123.py文件可用的位置

from PyInstaller.utils.hooks import collect_data_files

#Instruct pyinstaller to collect data files from resources package.
datas = collect_data_files('resources')

因为这是错误C:\ Users \ my_username \ AppData \ Local \ Temp \ _MEI175682 \ resources \ template.json“resources”是您必须从中获取数据文件的包。

现在从123.py文件夹中的命令窗口中运行以下命令

pyinstaller --onefile --additional-hooks-dir =。 123.py

exe将创建运行exe并检查它是否正在获取数据文件。

感谢Panda1100

© www.soinside.com 2019 - 2024. All rights reserved.