【问题标题】:Pyinstaller --onefile warning file already exists but should notPyinstaller --onefile 警告文件已经存在但不应该
【发布时间】:2022-05-05 15:14:01
【问题描述】:

运行 Pyinstaller --onefile 并启动生成的 .exe 时,会出现多个弹出窗口并显示以下警告:

WARNING: file already exists but should not: C:\Users\myuser\AppData\Local\Temp\_MEI90082\Cipher\_AES.cp37-win_amd64.pyd

这使得.exe 难以使用,即使单击警告仍然允许.exe 正常运行。

如何摆脱这些警告?

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    将其放在这里以防万一,因为我花了一些时间来了解如何做到这一点。

    在您的 pyinstaller 项目的 .spec 中,将其添加到 a = Analysis(...) 行之后:

    # Avoid warning
    to_remove = ["_AES", "_ARC4", "_DES", "_DES3", "_SHA256", "_counter"]
    for b in a.binaries:
        found = any(
            f'{crypto}.cp37-win_amd64.pyd' in b[1]
            for crypto in to_remove
        )
        if found:
            print(f"Removing {b[1]}")
            a.binaries.remove(b)
    

    当然,您可以调整数组 to_remove 以及确切的文件名 .cp37-win_amd64.pyd 以匹配出现在警告中的文件。

    这会导致文件不包含在.exe 中,并且警告消失了。

    【讨论】:

    • 嗨,这里描述的 PySide6 有类似的问题stackoverflow.com/questions/69790852/… 我尝试了上面答案中描述的“found = any”方法。但有些文件没有被删除。有什么建议吗?
    【解决方案2】:

    我几乎有同样的问题。
    不是一个好主意 - 删除您正在迭代的列表的一部分。
    试试这个:

    from PyInstaller.building.datastruct import TOC
    
    # ...
    # a = Analysis(...)
    
    x = 'cp36-win_amd64'
    datas_upd = TOC()
    
    for d in a.datas:
        if x not in d[0] and x not in d[1]:
            datas_upd.append(d)
    
    a.datas = datas_upd
    
    

    【讨论】:

      猜你喜欢
      • 2021-12-15
      • 2013-10-04
      • 1970-01-01
      • 2019-06-13
      • 2012-12-06
      • 2014-12-22
      • 2020-01-28
      • 2013-05-18
      • 2018-02-21
      相关资源
      最近更新 更多