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

6.6k views Asked by At

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

4

There are 4 answers

3
Bangzhuo Song On

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.

4
Lukas On

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
1
Somesh Bagadiya On

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

1
Franky1 On

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