【问题标题】:FileNotFoundError [Errno 2] when running pyinstaller executable?运行 pyinstaller 可执行文件时出现 FileNotFoundError [Errno 2]?
【发布时间】:2019-08-13 17:30:41
【问题描述】:

我正在尝试使用 Pyinstaller 将我的 python 文件作为可执行文件。转换过程完成后,在我的 dist 文件夹中,当我单击“myApplication.exe”时,出现以下错误: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Desktop\\Application\\dist\\myApplication\\smart_open\\VERSION' [17416] Failed to execute script myApplication

我已经搜索过这个问题的答案,但没有一个有我的特定错误,即文件夹 smart_open\VERSION,因为我不知道那应该是什么。

编辑

smart_open 文件夹甚至不存在于我的 myApplication 文件夹中

【问题讨论】:

  • VERSION 是包含版本号的文本文件吗?
  • 我什至没有 smart_open 文件夹来拥有 VERSION,不知道发生了什么
  • 你的应用使用pip包smart_open吗?
  • 该包位于Lib\site-packages 文件夹中,但是我的应用程序没有导入它,除非其他一些库将其作为依赖项?不确定。
  • 也许this answer 可以帮助你,它是关于隐藏导入的。 Lib\site-packages\smart_open中是否有版本文件?

标签: python windows pyinstaller


【解决方案1】:

不要使用“smart_open”的原始版本,而是使用这个库的分支:https://github.com/rs-trevor/smart_open

拉取请求在这里:https://github.com/RaRe-Technologies/smart_open/pull/344

它本质上将奇怪的(无扩展名)“VERSION”文件转换为“version.py”,因此 pyinstaller 可以正确选择它

我在 smart_open github 中发布了同样的问题:https://github.com/RaRe-Technologies/smart_open/issues/345

【讨论】:

    【解决方案2】:

    我认为你必须在spec文件中添加smart_open的VERSION文件。更多信息在documentation。

    编辑

    在这种情况下,datas 行应该是:

    datas=[ ('c:\\python360564\\lib\\site-packages\\smart_open\\VERSION', 'smart_open\\VERSION' )], 
    

    第一部分是文件的初始路径,第二部分是目标路径(从错误消息中获取)。

    【讨论】:

    • 我尝试了你上面提到的技术(几种不同的方法)@ndclt,但它对我不起作用。我基本上是在“.spec”文件datas=[ ('c:\\python360564\\lib\\site-packages\\smart_open\\VERSION', '.' )], 中执行此操作的,但错误仍然发生。
    • 我认为应该替换元组中第二个表达式的.。我尝试编辑了我的答案。
    猜你喜欢
    • 1970-01-01
    • 2022-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    相关资源
    最近更新 更多