Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How transform a python program .py in an executable program in Ubuntu? [duplicate]

I have a simple python program and I want an executable version (for Ubuntu Linux) of this program to avoid running it in the terminal with python myprogram.py.

How can I do that ?

like image 417
xRobot Avatar asked Oct 18 '10 09:10

xRobot


People also ask

Can py be converted to exe?

In this section, we can also modify the path for where we want to export the files generated by our executable file: to do this, select the “Settings” toggle option and browse to the output directory of your choosing. The last step is to select “Convert . py to .exe” to convert our Python file.

How do I make a Python script executable in Linux?

Run the following command in your terminal to make the script executable: chmod +x SCRIPTNAME.py. Now, ​simply type ./SCRIPTNAME.py to run the executable script.


1 Answers

There is no need to. You can mark the file as executable using

chmod +x filename 

Make sure it has a shebang line in the first line:

#!/usr/bin/env python 

And your linux should be able to understand that this file must be interpreted with python. It can then be 'executed' as

./myprogram.py 
like image 97
relet Avatar answered Oct 02 '22 15:10

relet