【问题标题】:pyinstaller FileNotFoundError: [Errno 2] No such file or directory with --onefile onlypyinstaller FileNotFoundError: [Errno 2] 只有 --onefile 没有这样的文件或目录
【发布时间】:2022-10-15 08:10:49
【问题描述】:

我的 exe 文件无法找到该文件夹​​,虽然我已经添加了 datas.

首先我创建 .spec 文件

pyinstaller --onefile app.py --name myapp

然后我编辑.spec文件如下

datas=[('models','models'),('nltkdata','nltkdata')],

然后我做

python -m PyInstaller myapp.spec

现在当我运行exe时,它会抛出这个错误

FileNotFoundError: [Errno 2] No such file or directory: 'models/logisticregression.pkl'

这是目录结构

编辑: 如果我以这种方式调用我的应用程序,它会起作用

dist/myapp 

但是如果我 cd 进入 dist 它就不起作用 然后做

./myapp

编辑2: 如果我删除了--onefile。它的工作。但我想要一个文件

【问题讨论】:

  • 确保您在 dist 中运行 exe 而不是构建
  • 是的,我正在运行 dist 文件夹中的那个
  • 创建minimal reproducible example 或指向 github 存储库的链接

标签: python pyinstaller


【解决方案1】:

在 Windows 上,我必须将我的数据提供给 .spec 文件,如下所示:

datas=[('./models','models'), ('./nltkdata','nltkdata')]

【讨论】:

  • 不工作。我也认为它应该工作,但它不工作
猜你喜欢
  • 1970-01-01
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 2021-08-24
  • 2021-03-07
相关资源
最近更新 更多