-3

I use python 2.7 and I am wondering how can I change my python code into a linux executable file very similar to using gcc -o hello hello.c but with python

  • "You generally don't" is still the case. Almost all of the tools for this just bundle the Python interpreter, your original script, and that script's library dependencies *into* one big, slow-to-start executable. – Charles Duffy Mar 17 '18 at 16:46
  • well I found a file which will convert it – Goten Black Mar 19 '18 at 20:25
  • That "converted" script is almost certainly one big, slow-to-start executable containing the Python interpreter and the text (or .pyc/pyo bytecode) of your script and its library dependencies... as I just described above. – Charles Duffy Mar 19 '18 at 20:28
  • It works fast and it isnt .pyc or anything even close – Goten Black Mar 19 '18 at 20:32
  • I'll believe it (for arbitrary executables with arbitrary library dependencies) if and when I see it, and not before. Keep in mind that your executable can *contain* a `.pyc` (ie. in a zip file appended after the executable header at the front of the binary) without that being obvious to you-the-user... but a reverse engineer will have no trouble breaking that open and getting at your original code. – Charles Duffy Mar 19 '18 at 20:36
  • Similarly, speaking to "works fast" -- how many seconds does it take to start your program 1000 times, as compared to the original native-Python version on the same hardware? – Charles Duffy Mar 19 '18 at 20:38

1 Answers1

0

You generally don't.

Instead you add a so-called shebang in the file, and change the flags to make it executable.

So the first line should be something like

#!/usr/bin/python2.7
# The rest of your code...

And then chmod u+x your_file.py.

Then you can simply run it like any other program, as in ./your_file.py.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621