What do I use on linux to make a python program executable
Solution 1:
Just put this in the first line of your script :
#!/usr/bin/env python
Make the file executable with
chmod +x myfile.py
Execute with
./myfile.py
Solution 2:
If you want to obtain a stand-alone binary application in Python try to use a tool like py2exe or PyInstaller.
Solution 3:
You can use PyInstaller. It generates a build dist so you can execute it as a single "binary" file.
http://pythonhosted.org/PyInstaller/#using-pyinstaller
Python 3 has the native option of create a build dist also:
https://docs.python.org/3/distutils/builtdist.html
Solution 4:
Putting these lines at the starting of the code will tell your operating systems to look up the binary program needed for the execution of the python script i.e it is the python interpreter.
So it depends on your operating system where it keeps the python interpreter. As I have Ubuntu as operating system it keeps the python interpreter in /usr/bin/python
so I have to write this line at the starting of my python script;
#!/usr/bin/python
After completing and saving your code
Start your command terminal
Make sure the script lies in your present working directory
Type
chmod +x script_name.py
Now you can start the script by clicking the script. An alert box will appear; press "Run" or "Run in Terminal" in the alert box; or, at the terminal prompt, type
./script_name.py
Solution 5:
If one want to make executable hello.py
first find the path where python is in your os with : which python
it usually resides under "/usr/bin/python" folder.
at the very first line of hello.py
one should add : #!/usr/bin/python
then through linux command chmod
one should just make it executable like : chmod +x hello.py
and execute with ./hello.py