How to make a program convert a .PY file to .EXE without human intervention and without GUI

Question:

After running my python program a myFile.py file has been created that contains some code. I want my program to not only create myFile.py but also convert it to myFile.exe.

auto-py-to-exe or any alternative that have the same problem isn’t a solution because I need to manually select the file that I want to convert in a GUI to convert it, I need my program to convert it.

Asked By: The_Fishy

||

Answers:

I’ll be using the cx_Freeze library to convert .py to .exe.
To install the package enter the command python -m pip install pypiwin32 in the terminal.

import win32com.client

tempFile = open(os.path.abspath("temp\temp.py"), 'w')
your_File = 'yourFile.py'
print("import sysnfrom cx_Freeze import Executable, setupnnnbase = Nonenif sys.platform == "win32":n    base = "Win32GUI"nexecutables = [Executable(r"" + yourFile + "", base = base)]nnsetup(n    name="exe_File",n    version="0.1",n    description="Sample cx_Freeze script",n    executables=executables,n)", file = tempFile)
tempFile.close()

os.system("python "temp\temp.py" build")
Answered By: The_Fishy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.