I have written a simple python script, and I need to run it as an executable, i.e., without the 'python' word at the beginning of the program. The script (simple_prog.py) is :
#!C:\Python27\python.exe
print "Hello World"
Whenever I am running the script as 'python simple_prog.py', it is printing the output alright, but without that, it is printing nothing (image below).
I have also referred to the "How do I make Python scripts executable?" section in the site https://docs.python.org/3/faq/windows.html#id3, from the stackoverflow question How to make python scripts executable on Windows? , but could not understand the solution.
Thanks.
Update :
Solved the problem from the stackoverflow link : Set up Python on Windows to not type python in cmd
This is what I followed (image below)
Please note the position of double-quotes in the ftype command.
The second command (simple_prog) ran successfully because I updated the PATHEXT variable by adding ".PY" in it.
Thanks for the responses as well as the downvotes.
The only realistic way to run a script on Windows without installing Python, is to use py2exe to package it into an executable. Py2exe in turn examines your script, and embeds the proper modules and a python interpreter to run it.
py2exe is a Python extension which converts Python scripts (. py) into Microsoft Windows executables (.exe). These executables can run on a system without Python installed. It is the most common tool for doing so.
You can run multiple instances of a python script from a shell however from within a python program without the use of multithreading/multiprocessing the GIL limitation will impact what you are trying to do.
Prerequisites: Install py2exe v0.6.9 which is compatible with python 2.7
Follow below Steps:
1.Save your code in to test.py (or any name with .py extension) file. Make sure that the code works fine by running it using python.
2.Then create a new file with name setup.py and paste the following code in to it.
from distutils.core import setup
import py2exe
setup(console=['test.py'])
3.Now it is time to run the script and create the executable. To build the executable, run "python setup.py py2exe" on the command prompt.
4.After Building the executable is finished. Now you can find test.exe in the \dist sub folder. Move to dist sub folder and run test.exe, you can see output in console.
Hope it helps you..!!
Thanks
You should associate .py
files to be run in Python. Of course, this approach requires Python to be installed, unlike converting to .exe
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With