How to make python scripts executable on Windows?
This sums it up better than I can say it:
http://docs.python.org/faq/windows.html
More specifically, check out the 2nd section titled "How do I make Python scripts executable?"
On Windows, the standard Python installer already associates the
.py
extension with a file type (Python.File
) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*
). This is enough to make scripts executable from the command prompt asfoo.py
. If you’d rather be able to execute the script by simple typingfoo
with no extension you need to add.py
to thePATHEXT
environment variable.
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!).
Convert python script to an executable file or icon for Windows?
Yes, it is possible following library's help with this.
PyInstaller can be used, under Mac OS X, Windows, Linux,...
For an example i would read this medium post, it should contain everything to get you started.
py2exe can be used if you only want an executable for the Windows platform.
How to create an executable from a Python script in Windows that can run on a Mac?
I can think of three solutions to your case and I hope it provides useful information:
The easiest solution is to install Python that someone's Mac and use py2app to create a Mac executable so that they can delete Python later and just keep the executable file.
Tell them to install winebottler, one of the many solutions to run Windows executables on Mac. Keep in mind that since Mac OS Catalina, Macs only run 64-bit applications, so make sure you use a 64-bit Python Version if you go with this option.
It is possible to run Mac on your Windows machine using an Oracle VirtualMachine VirtualBox or similar (shown in this tutorial). You would still have to install the version of Python you are running along with the necessary libraries and your script/files with yourself through something like Github or Dropbox. You will need a significant amount of extra RAM to run Mac OS on Windows and not hate your life while at it.
As someone who has been down that road because my job demanded me to, I highly recommend the first option, it's the shortest one and it doesn't demand any sort of IT prowess from the person you are sharing the application with. Also, as someone not too experienced with Mac OS, I feel like Apple makes it tricky to build executable files that run in more than one of their OS versions.
How do I make a python script executable?
Add a shebang line to the top of the script:
#!/usr/bin/env python
Mark the script as executable:
chmod +x myscript.py
Add the dir containing it to your
PATH
variable. (If you want it to stick, you'll have to do this in.bashrc
or.bash_profile
in your home dir.)export PATH=/path/to/script:$PATH
Related Topics
Script Using Multiprocessing Module Does Not Terminate
Python Serialization - Why Pickle
Remove Namespace and Prefix from Xml in Python Using Lxml
Can Existing Virtualenv Be Upgraded Gracefully
Pip - Fatal Error in Launcher: Unable to Create Process Using '"'
What Limitations Have Closures in Python Compared to Language X Closures
Concatenate Two Numpy Arrays Vertically
Underscore VS Double Underscore with Variables and Methods
Principal Component Analysis (Pca) in Python
Nested Dictionary to Multiindex Dataframe Where Dictionary Keys Are Column Labels
Python Read JSON File and Modify
How to Move Pandas Data from Index to Column After Multiple Groupby
Add Params to Given Url in Python
Matplotlib: How to Plot Images Instead of Points
How to Hide the Console Window in a Pyqt App Running on Windows
Shuffle an Array with Python, Randomize Array Item Order with Python