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
How to Use an Image for the Background in Tkinter
Replacing Column Values in a Pandas Dataframe
Finding Multiple Occurrences of a String Within a String in Python
How to Print to Stderr in Python
How to Remove All Characters After a Specific Character in Python
Access Elementtree Node Parent Node
Why Does Python Print Unicode Characters When the Default Encoding Is Ascii
Concatenate a Numpy Array to Another Numpy Array
Importerror After Successful Pip Installation
Get the Key Corresponding to the Minimum Value Within a Dictionary
Converting String with Utc Offset to a Datetime Object
Difference Between Filter and Filter_By in SQLalchemy
How to Set Environment Variables in Pycharm
Differencebetween 'Same' and 'Valid' Padding in Tf.Nn.Max_Pool of Tensorflow
How to Validate a Url in Python? (Malformed or Not)
Color by Column Values in Matplotlib