Search code examples
pythonpyinstaller

Pyinstaller --onefile warning file already exists but should not


When running Pyinstaller --onefile, and starting the resulting .exe, multiple popups show up with the following warning:

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

This makes the .exe hard to use even though clicking through the warnings still allows the .exe to run properly.

How to get rid of these warnings ?


Solution

  • Going to put this here in case it helps anyone, since I spent some time finding out how to do this.

    in the .spec of your pyinstaller project, add this after the line 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)
    

    Of course you may adapt the array to_remove as well as the exact file name .cp37-win_amd64.pyd to match the files that show up in your warnings.

    This results in the files not being included in the .exe and the warnings are gone.