How Transform a Python Program .Py in an Executable Program in Ubuntu

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

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

What do I use on linux to make a python program executable

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

How to make python program .py executable?

I just want when I write the program name "executable_program" in
terminal it runs without the "./" and the ".py"

You need to do the following things:

  1. Add the shebang at the top of your file, #!/usr/bin/python

  2. Make the file executable chmod +x foo.py

  3. Move it to somewhere that is in your $PATH, for example /usr/local/bin

To get rid of the .py, simply rename the file: sudo cp foo.py /usr/local/bin/foo

burhan@sandbox:~/pytemp$ cat foo.py
#!/usr/bin/python
print('Hello World!')
burhan@sandbox:~/pytemp$ chmod +x foo.py
burhan@sandbox:~/pytemp$ sudo cp foo.py /usr/local/bin/foo
burhan@sandbox:~/pytemp$ foo
Hello World!

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!).



Related Topics



Leave a reply



Submit