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
正确地 运行。
如何摆脱这些警告?
将它放在这里以防它对任何人有帮助,因为我花了一些时间来了解如何做到这一点。
在您的 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
中并且警告消失。
我也遇到了几乎相同的问题。
不是一个好主意 - 删除您正在迭代的列表的一部分。
试试这个:
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
当 运行 宁 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
正确地 运行。
如何摆脱这些警告?
将它放在这里以防它对任何人有帮助,因为我花了一些时间来了解如何做到这一点。
在您的 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
中并且警告消失。
我也遇到了几乎相同的问题。
不是一个好主意 - 删除您正在迭代的列表的一部分。
试试这个:
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