[英]python PyInstaller created executable failed to run the exe Error: cannot find Temp\\_MEI175682 (data file)
Using PyInstaller created an exe for my script and while running the exe it throws the following error where as if i run the .py file no issues found. 使用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
I've supplied all the proper flags for the data to be included by PyInstaller and the creation of the exe passed successfully. 我已经为PyInstaller包含的数据提供了所有正确的标志,并成功传递了exe的创建。
I have used --add-data
flag and I have used data
field in the spec file. 我使用了
--add-data
标志,我在spec文件中使用了data
字段。
[Edit this line and add exact command you have given for creating exe] [编辑此行并添加您为创建exe所提供的确切命令]
Did deepdive in the error given directory path where no such directory or file exist. 在给定目录路径的错误中深入了解了没有这样的目录或文件的情况。 Could not locate Temp\\_MEI175682
无法找到Temp \\ _MEI175682
'C:\\Users\\my_username\\AppData\\Local\\Temp\\_MEI175682\\resources\\template.json'
The pyinstaller is intalled in .\\scripts\\ directory ;why pyinstaller is looking the .json file in the above directory where the file does not exist. pyinstaller安装在。\\ scripts \\目录中;为什么pyinstaller在上面目录中查找文件不存在的.json文件。
Also the file(template.json') is there in the .\\scripts\\template.json directory. 文件(template.json')也在。\\ scripts \\ template.json目录中。
To solve this issue what is the best way ? 要解决这个问题,最好的方法是什么? 1.Should something be added in the environment variable to resolve this?
1.应该在环境变量中添加一些东西来解决这个问题吗? 2.Should i create single file .exe by running the script from .\\scripts\\pyinstaller folder only ?
2.我应该通过从。\\ scripts \\ pyinstaller文件夹运行脚本来创建单个文件.exe吗? 3. Supplying any details to .spec file or adding certain details to .spec file after pyinstaller creating it would help solving this problem?
3.在pyinstaller创建它之后,向.spec文件提供任何细节或向.spec文件添加某些细节将有助于解决这个问题?
Any help that would solve the problem with details is much appreciated.Thanks in advance. 任何帮助解决问题的细节都非常感谢。谢谢。 Thanks in advance.
提前致谢。
This will be the easy and clean solution,Check and like and vote. 这将是简单而干净的解决方案,检查和喜欢并投票。
When you're encountering following error. 当您遇到以下错误时。
IOError: [Errno 2] No such file or directory: 'C:\\Users\\username\\AppData\\Local\\Temp\\_MEI502322\\resources\\template.json'
This solution tested under Python 2.7.10 and Pyinstaller 3.0. 此解决方案在Python 2.7.10和Pyinstaller 3.0下测试。
Put this file to your script folder. 将此文件放入脚本文件夹。 where your .py script available example 123.py
您的.py脚本可用示例123.py
Add this hook to your distribution it means add this in below in new file, example xyx.py and keep this file where the 123.py file available 将此挂钩添加到您的发行版中它意味着在下面的新文件中添加它,例如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')
since this is the error C:\\Users\\my_username\\AppData\\Local\\Temp\\_MEI175682\\resources\\template.json " resources " is the package where from you have to take the data file. 因为这是错误C:\\ Users \\ my_username \\ AppData \\ Local \\ Temp \\ _MEI175682 \\ resources \\ template.json“ resources ”是您必须从中获取数据文件的包。
Now run the following in command window from your 123.py folder 现在从123.py文件夹中的命令窗口中运行以下命令
pyinstaller --onefile --additional-hooks-dir=.
pyinstaller --onefile --additional-hooks-dir =。 123.py
123.py
exe will be created run the exe and check it is taking the data file. exe将创建运行exe并检查它是否正在获取数据文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.