__pycache__, one more good reason to stck with Python 2?

Martin v. Loewis martin at v.loewis.de
Thu Jan 20 20:19:47 EST 2011


> I know I've seen problems executing .pyc files from the shell in the 
> past... perhaps I was conflating details of something else. Ah, I know!
> 
> [steve at sylar ~]$ chmod u+x toto.pyc
> [steve at sylar ~]$ ./toto.pyc
> : command not found ��
> ./toto.pyc: line 2: syntax error near unexpected token `('
> ./toto.pyc: line 2: `P7Mc at s     dGHdS(tfooN((((s        ./
> toto.py<module>s'

Works fine here:

martin at mira:/tmp$ cat >a.py
print "Hello, world"
martin at mira:/tmp$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
py> import a
Hello, world
py>
martin at mira:/tmp$ chmod +x a.pyc
martin at mira:/tmp$ ./a.pyc
Hello, world

Notice that it is a Linux feature that it can support Python bytecode
as a "native" executable when properly configured.

Windows has a very similar feature, though. I think OSX can support
it as well, but I haven't tried.

Regards,
Martin



More information about the Python-list mailing list