*win32ctypes.pywin32.pywintypes.error when using pyinstaller in VS Code - Possible Virus/Trojan?
Asked Answered
G

5

12

I am using pyinstaller to generate an executable code for my python.py file. However, I am getting this error:

File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\utils\win32\icon.py", line 143, in CopyIcons_FromIco
    hdst = win32api.BeginUpdateResource(dstpath, 0)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32ctypes\pywin32\win32api.py", line 208, in BeginUpdateResource
    with _pywin32error():
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
**win32ctypes.pywin32.pywintypes.error: (225, 'BeginUpdateResourceW', 'Operation did not complete successfully because the file contains a virus or potentially unwanted software.')**

My antivirus is allegating there is a virus when running pyinstaller: Trojan:Win64/Malgent!MSR

I tried to uninstall python, reinstall, and nothing

Genus answered 5/10, 2023 at 17:50 Comment(1)
What is interesting is that when scanning the Python files with antivirus there is no virus alert. Only when pyinstaller starts running to generate the .exe file the antivirius alerts...Genus
M
24

I had a similar issue today when using the latest pyinstaller (6.X.X) on Windows 11. For me, changing to an older release (5.13.2) fixed the issue.

To install 5.13.2 you can use pip module with following:

pip install pyinstaller==5.13.2
Medulla answered 7/10, 2023 at 17:26 Comment(4)
Thank you very much @Lukas. It worked! I used the command pip install pyinstaller==5.13.2 to install previous pyisntaller version.Genus
Thank you @Medulla this also worked for me. I also noticed that pyinstaller v6.3 appname.py would work but then trying to run from the resulting spec file didn't giving the error above.Caster
@ByteInsight same error by me with pyinstaller 6.3.0Adenoid
The official response from pyinstaller is here github.com/pyinstaller/pyinstaller/issues/6062 (and yes it has a really misleading title but I am sure it's the official position because if you try to report a false positive antivirus detection you get this exact text)Rani
I
5

Try not using -w in pyinstaller. Previously, I used…

pyinstaller --onefile -w image.py 

…and got the same problem. But when I do…

pyinstaller --onefile image.py 

…it is good.

Incoherence answered 6/10, 2023 at 22:50 Comment(3)
Ok, it compiles. But you lose the 'windowed' feature. Not a solution if you need the app windowed, without command line console.Gipps
It means that your app will use python rather than pythonw, or in other words, the app will run from a console that will stick to it for the whole runtime, which is usually undesirable for GUI applications. It works though. I preferred to just revert Pyinstaller to the latest 5.x version and keep the -w argument.Subscription
use --noconsole flag to hide the console.Alar
W
5

You can exclude your project folder from the windows virus check:

  • Start -> Settings -> Privacy & Security -> Virus & threat protection
  • manage settings -> exclusions -> add or remove exclusions
  • add your project folder
Warrenwarrener answered 18/1, 2024 at 12:47 Comment(1)
More specifically on Windows 10: Windows settings --> Update & security --> Windows security --> Virus & threat protection --> Virus & threat protection settings [manage settings] --> Exclusions --> Add exclusionWestfalen
T
1

Open powershell as admin and type this command to exclude your project folder:

Set-MpPreference -ExclusionPath "path"   # paste your path inside the double quotes as you may have spaces between folder names

Then in the same powershell windows type cd "project_path" then run your pyinstaller commands.

Tasteful answered 1/6, 2024 at 12:23 Comment(0)
S
0

Turn off the Windows built-in real-time protection or deactivate the antivirus, and this action should resolve the issue.

Shannonshanny answered 16/1, 2024 at 9:35 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rubetta

© 2022 - 2025 — McMap. All rights reserved.