Problems compiling python
Erik Max Francis
max at alcyone.com
Sun Jan 4 16:15:37 EST 2004
Florian Lindner wrote:
> I want to compile that small python script:
...
> bastet:/ # chmod u+x test.pyc
> bastet:/ # ./test.pyc
> ./test.pyc: line 1: syntax error near unexpected token `;'
> '/test.pyc: line 1: `;ò
> bastet:/ #
>
> What is wrong?
A compiled Python file (.pyc) is not an executable. (Specifically, in
the Unix world, it does not contain a bangpath.) Instead, just pass it
as an argument to the Python interpreter:
max at oxygen:~/tmp% cat > hello.py
print "Hello, world!"
^D
max at oxygen:~/tmp% python
Python 2.3.3 (#1, Dec 22 2003, 23:44:26)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_compile
>>> py_compile.compile('hello.py')
>>> ^D
max at oxygen:~/tmp% ls hello.py*
hello.py hello.pyc
max at oxygen:~/tmp% rm hello.py
max at oxygen:~/tmp% python hello.pyc
Hello, world!
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Granted that I must die, how shall I live?
-- Michael Novak
More information about the Python-list
mailing list