簡體   English   中英

Pyinstaller --onefile 警告文件已經存在但不應該存在

[英]Pyinstaller --onefile warning file already exists but should not

運行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正常運行。

如何擺脫這些警告?

我有幾乎相同的問題。
這不是一個好主意 - 刪除您正在迭代的列表的一部分。
嘗試這個:

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

把它放在這里以防它對任何人有幫助,因為我花了一些時間來找出如何做到這一點。

.spec項目的 .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中,並且警告消失了。

與遇到警告消息、記錄它們並創建一個用於在 .spec 文件中排除它們的可迭代對象一樣好,如果我們不必通過該壓力過程,那就更好了。 讓我們試試吧。

觀察: 'datas' 和 'binaries' 的數據結構在 .spec 文件中是相同的。 即 [(module_or_file_name, absolute_path, type_DATA_or_BINARY), ...]

這里的方法是相同的,實現方式不同。 我們尋找已添加到a.datas並重復/重新添加到a.binaries 中的內容

方法 1 :[1-liner 但速度較慢]

# ...
# a = Analysis(...)

a.binaries = [b for b in a.binaries if not b in list(set(b for d in a.datas for b in a.binaries if b[1].endswith(d[0])))]  # The unique binaries not repeated in a.datas.

方法 2 :[更快]

# ...
# a = Analysis(...)

for b in a.binaries.copy():  # Traver the binaries.
    for d in a.datas:  #  Traverse the datas.
        if b[1].endswith(d[0]):  # If duplicate found.
            a.binaries.remove(b)  # Remove the duplicate.
            break

我在創建 Cython + PyInstaller + AES 加密 GUI 捆綁應用程序的簡化組合功能時使用了此實現。

希望這對將來的人有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM