How to convert a .py file to a .exe file?

fan2python31 Posted messages 1 Status Member -  
brucine Posted messages 24931 Registration date   Status Member Last intervention   -

Hello,

I am currently creating a game in Python as part of my final year NSI project, which takes the form of a PvP using Pygame, consisting of 5 code files and an assets folder. I would like to convert the script (.py) into an executable file (.exe). I've tried many things, watched tutorials, installed PyInstaller and auto-py-to-exe (which is a web graphical interface for running PyInstaller), but nothing has worked. When I use the Windows console with the command pyinstaller --onefile, even when changing the current folder or copying the path, I get an error (PyInstaller is not recognized as an executable command). When I use auto-py-to-exe, the console shows a few lines and successfully creates an .exe file in the chosen folder. However, when I run it, it gets deleted, and my antivirus reports it as having blocked a threat. I don't know what else to try, and I don't know where the problem lies. For your information, I am running Windows 11. If you could help me identify the issue and possibly resolve it, I would be very grateful.

Thank you in advance!

1 answer

  1. brucine Posted messages 24931 Registration date   Status Member Last intervention   4 179
     

    Hello,

    I don't use Python, but the first error indicates that the pyinstaller executable is not being run from the path where it is located, which means it must have been incorrectly specified (exact path, possible quotes...).

    The second one isn’t really one; back when I was using it, Windows Defender would remove all the cmd scripts I had written in the same way.

    We probably can't exclude a file that doesn't exist yet, but we can surely do it from its destination folder, even if it means creating one for that purpose (at least that's what I do, this time with Comodo).

    0