Error message "OSError(22, 'Invalid argument')" during build

22 views
Skip to first unread message

David

unread,
May 21, 2024, 7:17:26 AMMay 21
to PyInstaller
Hi!

I'm trying to build an exe file but I'm getting an error which I don't understand, "OSError(22, 'Invalid argument')". It seems to be retrying a certain number of times, but then crashes. Can someone explain what might be causing this error? 

I've attached the console log below. I can provide the Python source code, but it probably wouldn't be of much help.

Thanks.

(sound) E:\Python\ThinkDSP-master\code>pyinstaller drone.py --onefile
3659 INFO: PyInstaller: 6.6.0, contrib hooks: 2024.6
3660 INFO: Python: 3.12.3 (conda)
3716 INFO: Platform: Windows-10-10.0.19045-SP0
3723 INFO: wrote E:\Python\ThinkDSP-master\code\drone.spec
3735 INFO: Extending PYTHONPATH with paths
['E:\\Python\\ThinkDSP-master\\code']
4862 INFO: checking Analysis
6261 INFO: checking PYZ
7128 INFO: checking PKG
8015 INFO: Bootloader C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\run.exe
8016 INFO: checking EXE
8017 INFO: Building because name changed
8018 INFO: Building EXE from EXE-00.toc
8065 INFO: Copying bootloader EXE to E:\Python\ThinkDSP-master\code\dist\drone.exe
8142 INFO: Copying icon to EXE
8194 INFO: Copying 0 resources to EXE
8194 INFO: Embedding manifest in EXE
8241 INFO: Appending PKG archive to EXE
68911 INFO: Fixing EXE headers
69456 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #1 / 20: OSError(22, 'Invalid argument'). Retrying in 0.05 second(s)...
70090 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #2 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
70742 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #3 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
71494 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #4 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
72129 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #5 / 20: OSError(22, 'Invalid argument'). Retrying in 0.07 second(s)...
72767 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #6 / 20: OSError(22, 'Invalid argument'). Retrying in 0.07 second(s)...
73452 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #7 / 20: OSError(22, 'Invalid argument'). Retrying in 0.08 second(s)...
74100 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #8 / 20: OSError(22, 'Invalid argument'). Retrying in 0.08 second(s)...
74798 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #9 / 20: OSError(22, 'Invalid argument'). Retrying in 0.09 second(s)...
75626 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #10 / 20: OSError(22, 'Invalid argument'). Retrying in 0.10 second(s)...
76290 WARNING: Execution of 'set_exe_build_timestamp' failed on attempt #11 / 20: OSError(22, 'Invalid argument'). Retrying in 0.11 second(s)...
113109 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #1 / 20: OSError(22, 'Invalid argument'). Retrying in 0.05 second(s)...
113839 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #2 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
115035 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #3 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
116036 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #4 / 20: OSError(22, 'Invalid argument'). Retrying in 0.06 second(s)...
116883 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #5 / 20: OSError(22, 'Invalid argument'). Retrying in 0.07 second(s)...
117746 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #6 / 20: OSError(22, 'Invalid argument'). Retrying in 0.07 second(s)...
118614 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #7 / 20: OSError(22, 'Invalid argument'). Retrying in 0.08 second(s)...
119393 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #8 / 20: OSError(22, 'Invalid argument'). Retrying in 0.08 second(s)...
120169 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #9 / 20: OSError(22, 'Invalid argument'). Retrying in 0.09 second(s)...
120972 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #10 / 20: OSError(22, 'Invalid argument'). Retrying in 0.10 second(s)...
121735 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #11 / 20: OSError(22, 'Invalid argument'). Retrying in 0.11 second(s)...
122533 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #12 / 20: OSError(22, 'Invalid argument'). Retrying in 0.12 second(s)...
123453 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #13 / 20: OSError(22, 'Invalid argument'). Retrying in 0.14 second(s)...
124391 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #14 / 20: OSError(22, 'Invalid argument'). Retrying in 0.17 second(s)...
125190 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #15 / 20: OSError(22, 'Invalid argument'). Retrying in 0.20 second(s)...
126180 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #16 / 20: OSError(22, 'Invalid argument'). Retrying in 0.25 second(s)...
127083 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #17 / 20: OSError(22, 'Invalid argument'). Retrying in 0.33 second(s)...
128058 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #18 / 20: OSError(22, 'Invalid argument'). Retrying in 0.50 second(s)...
159205 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #19 / 20: OSError(22, 'Invalid argument'). Retrying in 1.00 second(s)...
160831 WARNING: Execution of 'update_exe_pe_checksum' failed on attempt #20 / 20: OSError(22, 'Invalid argument').
Traceback (most recent call last):
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\api.py", line 1018, in _retry_operation
    return func(*args)
           ^^^^^^^^^^^
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\utils\win32\winutils.py", line 106, in update_exe_pe_checksum
    with open(exe_path, 'wb') as fp:
         ^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'E:\\Python\\ThinkDSP-master\\code\\dist\\drone.exe'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\user\anaconda3\envs\sound\Scripts\pyinstaller-script.py", line 10, in <module>
    sys.exit(run())
             ^^^^^
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\__main__.py", line 212, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\__main__.py", line 69, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\build_main.py", line 1186, in main
    build(specfile, distpath, workpath, clean_build)
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\build_main.py", line 1126, in build
    exec(code, spec_namespace)
  File "E:\Python\ThinkDSP-master\code\drone.spec", line 19, in <module>
    exe = EXE(
          ^^^^
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\api.py", line 643, in __init__
    self.__postinit__()
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
    self.assemble()
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\api.py", line 841, in assemble
    self._retry_operation(winutils.update_exe_pe_checksum, build_name)
  File "C:\Users\user\anaconda3\envs\sound\Lib\site-packages\PyInstaller\building\api.py", line 1037, in _retry_operation
    raise RuntimeError(f"Execution of {func_name!r} failed - no more attempts left!") from e
RuntimeError: Execution of 'update_exe_pe_checksum' failed - no more attempts left!

bwoodsend

unread,
May 21, 2024, 7:54:13 AMMay 21
to PyInstaller

That retry logic is trying to accommodate for security scans that intercept the EXE that PyInstaller is midway through building and temporarily block PyInstaller’s access to it. I guess the easiest thing to try would be to increase the timeout (e.g. change the first 1 to a 5.

David

unread,
May 21, 2024, 4:26:55 PMMay 21
to PyInstaller
Thanks. I did as you suggested, and also increased the number of attempts to 25 (line 959):

    def _retry_operation(func, *args, max_attempts=25):

But it still timed out. So I temporarily turned off my anti-virus software (Bitdefender) and it worked. The strange thing is that even with my AV software turned off, it still had to make as many as 18 attempts before successfully doing whatever it's doing. So maybe there's something else going on that's causing the delay.
Reply all
Reply to author
Forward
0 new messages