I get a virus alert when I convert my .py file into an .exe file. How do I fix it?

2.2k Views Asked by At

All I want is to convert my .py file into an .exe file but my PC is always deleting the finished .exe file when i use the preset of auto-py-to-exe to hide the cmd window which usually comes up when the .exe file gets started because it thinks the .exe file is or contains a virus. In general: Every time I try to hide the cmd window the .exe file gets detected as a virus.

I tried to use auto-py-to-exe to convert my .py file into an .exe file. And it actually works right as long as I don't choose to hide the cmd window, which always comes up if not specifically forbidden. Means: When I select the option to hide the cmd window before I convert it into an .exe file all my antivirus programs (Windows Defender and Avira) instantly ring all their alarms and delete the file on their own before i can do anything.

I also tried to do it with pyinstaller itself (I know auto-py-to-exe is based on it but i thought it couldn't hurt to try). There it is the same problem. As soon as i tell it to hide the command window when starting the program the .exe file gets detected as a virus (specifically a Trojan). In other words:

pyinstaller filename.py --onefile

works as intended. I get the .exe and everything works fine. But as soon as i use

pyinstaller filename.py -w

or

pyinstaller filename.py --noconsole

the virus alert goes off as soon as the .exe is created.

I also tried to use Nuitka and py2exe. But it didn't work as well and now i am all out of ideas.

I use Python 3.10

Does anyone know how to create a .exe file which hides the cmd window without causing a virus alert? I want to run it not only on my computer but also on my friends' PCs and i don't want them to get virus alerts (It is a management program supposed to make life easier for us. Not a virus.) Many thanks to everyone in advance!

1

There are 1 best solutions below

0
fgo On

This is a known issue with PyInstaller, many anti-virus programs detect programs made with it as false positives. Either build it with the console, or:

  1. Add the folder the built app is in as an exception.

    https://support.microsoft.com/en-us/windows/add-an-exclusion-to-windows-security-811816c0-4dfd-af4a-47e4-c301afe13b26

Select Start , then open Settings . Under Privacy & security , select Virus & threat protection.

Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions.

Select Add an exclusion, and then select from files, folders, file types, or process. A folder exclusion will apply to all subfolders within the folder as well.

  1. Submit a report to Microsoft Anti Virus saying it is a false positive, they can then fix it.

    https://www.microsoft.com/en-us/wdsi/filesubmission

  2. You can use VirusTotal to scan your file and see which anti-virus software is picking it up as a virus, it can also prove it is a false positive.

    https://www.virustotal.com/gui/home/upload

False positives with PyInstaller have been around for years, the amount has decreased recently, but its still an issue because of the way PyInstaller builds applications.

You can also try other methods, such as CxFreeze.