【问题标题】:Pyinstaller Tensorflow bundle failsPyinstaller Tensorflow 捆绑包失败
【发布时间】:2020-01-12 08:33:45
【问题描述】:

尝试运行 pyinstaller 在 windows 上编译 tensorflow 应用程序。该文件已完美打包,但在运行生成的 exe 时最终遇到此错误。

 File "site-packages\astor\__init__.py", line 24, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\me\\AppData\\Local\\Temp\\_MEI138162\\astor\\VERSION'

我确保包含astor 包,甚至尝试使用--hiden imports 标志,但无济于事。

如何在 pyinstaller 中正确包含 astor 包?

【问题讨论】:

    标签: python tensorflow pyinstaller


    【解决方案1】:

    您可以在项目中创建“astor”文件夹。 并从“your env/Lib/site-packages/astor/VERSION”粘贴 VERSION 文件。

    -- [编辑]--

    在 PyInstaller 上,您应该添加标志 --add-data 'astor:./astor' 以将文件夹添加到项目中,似乎不需要源代码,只需 VERSION 文件

    【讨论】:

    【解决方案2】:

    我遇到了同样的问题,这是我解决它的方法不需要任何手动复制/粘贴:

    在我的.spec 文件中,我添加了以下几行:

    from PyInstaller.utils.hooks import collect_data_files
    a.datas += collect_data_files('astor', subdir=None, include_py_files=False)
    

    说明

    错误指向站点包中的此语句astor/__init__.py:

    with open(os.path.join(ROOT, 'VERSION')) as version_file:
        __version__ = version_file.read().strip()
    

    似乎存在于 astor 包中的 VERSION 文件没有被 pyinstaller 复制,因此在生成的独立文件夹中找不到。使用collect_data_files() utils 函数并将结果添加到我的.spec 文件中的分析'datas 参数解决了这个问题。文档中的详细信息:https://pyinstaller.readthedocs.io/en/stable/hooks.html?highlight=collect_data_files#useful-items-in-pyinstaller-utils-hooks

    【讨论】:

    • 或者,在.spec文件中直接写datas=collect_data_files('astor')
    【解决方案3】:

    我通过进入 astor/init.py 文件并将您在问题中提到的两行更改为:

    解决了这个问题
    __version__ = '0.8.1'
    
    parse_file = code_to_ast.parse_file
    

    Pyinstaller 在此之后完美运行。

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题。我的 astor 软件包版本是 0.8.1。我将 astor 版本更改为 0.7.1。它就像一个魅力。

      【讨论】:

        猜你喜欢
        • 2015-06-05
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 2015-10-19
        • 1970-01-01
        • 2011-12-11
        相关资源
        最近更新 更多