Entry
i want to change a script file to be an executable file. How do i do that?
Oct 9th, 2003 12:09
Randy Kramer, chempaka biru,
I'm a newbie to Python, but since no one else has, let me try to answer
your question -- with some questions to start: ;-)
Do you want to "compile" the Python source (to something like an
intermediate P-code)? I don't know if that can be done.
Do you want to be able to cause the program to run just by typing the
name of the file? I'm sure that can be done, but you may need to do it
differently depending on your operating system.
In Linux (I'm fairly new to Linux also), I would put the code in a
file, name it anything you'd like, then:
* put a "shebang" line as the first line of the file, which looks
like "#! /bin/python" where /bin/python is the path to the python
executable on your system
* put the file in a directory that is on your path -- I'd suggest
/usr/bin
* set the file ownership and permissions appropriately using chown
and chmod -- for example, if my user name was "rhk", I'd probably do:
* "chown rhk.rhk my_file" to make me the owner of the file, and
also make it "owned" by my group (also named rhk)
* "chmod 755 my_file" to allow me to read, write, and execute the
file, and to allow the members of the "owning group" (rhk) and the
entire world to read and execute the file
In Windows (I left Windows before attempting to learn Python), hmm, I
don't know. I don't think it can be compiled to a .com or .exe -- one
thing that probably would work (if I knew the right syntax) would be to
create a one line .bat file with a command something like "python
--file=my_file" (with the correct syntax for invoking python and
specifying a file to run).