0

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
The_Fishy
  • 143
  • 10
  • Does this answer your question? [Create a single executable from a Python project](https://stackoverflow.com/questions/12059509/create-a-single-executable-from-a-python-project) – constantstranger Aug 02 '22 at 15:09
  • 1
    call pyinstaller with the os module (`os.system(your_command_calling_pyinstaller)`) – Achille G Aug 02 '22 at 15:16

1 Answers1

1

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 sys\nfrom cx_Freeze import Executable, setup\n\n\nbase = None\nif sys.platform == \"win32\":\n    base = \"Win32GUI\"\nexecutables = [Executable(r\"" + yourFile + "\", base = base)]\n\nsetup(\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")
The_Fishy
  • 143
  • 10