Pyinstaller - 文件未找到错误

4

我已经创建了一个Python脚本并将其转换为.exe文件,具体步骤如下:

Pyinstaller –-onefile RFOutputGraphs.py

虽然它可以工作,但是脚本中的一个任务失败了,尽管在Python中运行时完美地工作。

我的错误信息是:

      FileNotFoundError: [Errno 2] no such file or directory:
     'C:\\Users\\Nicholas\\AppData\\Local\\Temp\\_MEI30362\\currency_converter
     \\eurofxref-hist.zip'

我猜测它无法识别一个可能是不常见的模块(currencyconverter)。有没有修复这个问题的方法呢?谢谢。

1
尝试使用 --add-binary 选项。类似这样的命令 Pyinstaller --add-binary <path to zip>;currency_converter --onefile RFOutputGraphs.py - John Anderson
谢谢您的回复。我尝试了:Pyinstaller --add-binary <'C:\Users\Nicholas\AppData\Local\Temp\_MEI30362\currency_converter\eurofxref-hist.zip'>;currency_converter --onefile RFOutputGraphs.py,但它说找不到指定的路径。我查看了一下,发现它并不存在。嗯嗯 - Nicholas
1
请勿实际包含 '<' 和 '>'。您需要找到该 zip 文件的实际位置。错误消息中的路径是 Pyinstaller 期望找到它的地方,但它不在那里。这就是为什么会出现错误。添加该选项将从其实际位置(必须在选项中指定)复制 zip 文件到 Pyinstaller 期望找到它的位置。 - John Anderson
嘿,今天早上回到工作岗位,一切都运行得非常完美。谢谢你。如果你想把你的评论变成答案,我会标记它为已接受 :) - Nicholas
1个回答

6

您可以使用--add-binary选项将zip文件包含在由Pyinstaller创建的exe中,如下:

Pyinstaller --add-binary <path to zip>;currency_converter --onefile RFOutputGraphs.py 

这将从您的PC位置复制zip文件到.exe文件,并安排在运行.exe时将其提取到currency_converter文件夹(错误消息中提到的位置)。请查看使用 Pyinstaller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接