python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\ _ MEI175682(数据文件) [英] python PyInstaller created executable failed to run the exe Error: cannot find Temp\\_MEI175682 (data file)

查看:1006
本文介绍了python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\ _ MEI175682(数据文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PyInstaller为我的脚本创建了一个exe,并且在运行该exe时会引发以下错误,好像我在运行.py文件时未发现任何问题.

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.

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

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.

I've supplied all the proper flags for the data to be included by PyInstaller and the creation of the exe passed successfully.

我已经使用了--add-data标志,并且已经使用了规范文件中的data字段.

I have used --add-data flag and I have used data field in the spec file.

在给定的目录路径错误中深入研究了该目录或文件不存在的位置.找不到 Temp \ _MEI175682

Did deepdive in the error given directory path where no such directory or file exist. Could not locate Temp\_MEI175682

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

pyinstaller安装在.\ scripts \目录中;为什么pyinstaller在上述目录中查找不存在该文件的.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.

文件(template.json')也位于.\ scripts \ template.json目录中.

Also the file(template.json') is there in the .\scripts\template.json directory.

解决此问题的最佳方法是什么? 1.是否应在环境变量中添加某些内容来解决此问题? 2.我应该只通过运行.\ scripts \ pyinstaller文件夹中的脚本来创建单个文件.exe吗? 3.在pyinstaller创建后,向.spec文件提供任何详细信息或向.spec文件添加某些详细信息将有助于解决此问题?

To solve this issue what is the best way ? 1.Should something be added in the environment variable to resolve this? 2.Should i create single file .exe by running the script from .\scripts\pyinstaller folder only ? 3. Supplying any details to .spec file or adding certain details to .spec file after pyinstaller creating it would help solving this problem?

非常感谢能够解决细节问题的任何帮助.在此先感谢. 预先感谢.

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.

遇到以下错误时.

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下进行了测试.

This solution tested under Python 2.7.10 and Pyinstaller 3.0.

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

Put this file to your script folder. where your .py script available example 123.py

将此钩子添加到您的发行版中,这意味着将其添加到下面的新文件(例如xyx.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

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"资源"是从中获取数据文件的软件包

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.

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

Now run the following in command window from your 123.py folder

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

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

将创建exe,然后运行exe并检查其是否正在获取数据文件.

exe will be created run the exe and check it is taking the data file.

感谢 Panda1100

这篇关于python PyInstaller创建的可执行文件无法运行exe错误:找不到Temp \\ _ MEI175682(数据文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆