How to Make an Exe File from a Python Program

How can I make a Python script standalone executable to run without ANY dependency?

You can use py2exe as already answered and use Cython to convert your key .py files in .pyc, C compiled files, like .dll in Windows and .so on Linux.

It is much harder to revert than common .pyo and .pyc files (and also gain in performance!).

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

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")

Running an outside program (executable) in Python?

Those whitespaces can really be a bother. Try os.chdir('C:/Documents\ and\ Settings/') followed by relative paths for os.system, subprocess methods, or whatever...

If best-effort attempts to bypass the whitespaces-in-path hurdle keep failing, then my next best suggestion is to avoid having blanks in your crucial paths. Couldn't you make a blanks-less directory, copy the crucial .exe file there, and try that? Are those havoc-wrecking space absolutely essential to your well-being...?



Related Topics



Leave a reply



Submit