[Tutor] executing compiled python (.pyc) files

Sean 'Shaleh' Perry shalehperry@attbi.com
Fri, 05 Apr 2002 23:41:56 -0800 (PST)


On 06-Apr-2002 Justin khup wrote:
> 
> Hi there,
> 
>            When I execute a compiled python file (say file.pyc) like  "$
> python file.pyc"  in unix ,it works fine .
> 
>           But even after changing the mode to chmod +x and trying
> "$file.pyc", I can't execute getting the following error: 
> 
> Cannot execute binary file.
> play.pyc: Exec format error   
> 
>         What could be the reason since a compiled c code for example just
> works fine.
> 

the program loader does not know how to load a python pyc file.  It sees that
it is not in the normal executable format and complains.

Under linux (and I think the bsds) there is support for adding arbitrary
executable file types.  You can then tell the kernel that 'pyc' is to be run by
python.

If you tell python to run foo.py and there is a recent enough foo.pyc it will
use the pyc and ignore the .py.