Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options
cesmiga at gmail.com
Fri Jan 15 00:44:06 CET 2010
On Jan 14, 5:33 pm, "Martin v. Loewis" <mar... at v.loewis.de> wrote:
> > I've been playing with "Lua" and found something really cool that I'm
> > unable to do in "Python". With "Lua", a script can be compiled to byte
> > code using "luac" and by adding "#!/usr/bin/lua" at the top of the
> > binary, the byte code becomes a single file executable. After I found
> > this trick, I ran back to "Python" to give it a try. Well... it
> > didn't work. Is this possible?
> In Python, a different approach will work, depending on the operating
> E.g. on Linux, you can use binfmt_misc to make executables out of pyc
> code. Run
> import imp,sys,string
> magic = string.join(["\\x%.2x" % ord(c) for c in imp.get_magic()],"")
> reg = ':pyc:M::%s::%s:' % (magic, sys.executable)
> once on your Linux system (or, rather, at boot time), and all pyc
> files become executable (if the x bit is set).
> In Debian, installing the binfmt-support package will do that for
> Do "ls /proc/sys/fs/binfmt_misc/" to see what binary types are
> already supported on your system.
> P.S. The approach you present for Lua indeed does not work for
This works great! Do you or anyone else have information on how to do
the same thing for Windows and/or Solaris.
Thank you again,
More information about the Python-list