Problems compiling python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Florian Lindner

    Problems compiling python

    Hello,
    I want to compile that small python script:

    bastet:/ # cat test.py
    #!/usr/bin/python
    import sys, os
    username = os.getlogin()
    print username
    os.spawnv(os.P_ WAIT, "/root/mailboxmgm.py", sys.argv)

    Python 2.3.2 (#1, Oct 12 2003, 14:27:24)
    [GCC 3.2] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>> import py_compile
    >>> py_compile.comp ile("test.py")
    >>>[/color][/color][/color]
    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?

    Thanks,
    Florian
  • Erik Max Francis

    #2
    Re: Problems compiling python

    Florian Lindner wrote:
    [color=blue]
    > I want to compile that small python script:[/color]
    ...[color=blue]
    > 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?[/color]

    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@oxygen:~/tmp% cat > hello.py
    print "Hello, world!"
    ^D
    max@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.[color=blue][color=green][color=darkred]
    >>> import py_compile
    >>> py_compile.comp ile('hello.py')
    >>> ^D[/color][/color][/color]
    max@oxygen:~/tmp% ls hello.py*
    hello.py hello.pyc
    max@oxygen:~/tmp% rm hello.py
    max@oxygen:~/tmp% python hello.pyc
    Hello, world!

    --
    __ Erik Max Francis && max@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

    Comment

    • Florian Lindner

      #3
      Re: Problems compiling python

      Erik Max Francis wrote:
      [color=blue]
      > Florian Lindner wrote:
      >[color=green]
      >> I want to compile that small python script:[/color]
      > ...[color=green]
      >> 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?[/color]
      >
      > 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@oxygen:~/tmp% cat > hello.py
      > print "Hello, world!"
      > ^D
      > max@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.[color=green][color=darkred]
      >>>> import py_compile
      >>>> py_compile.comp ile('hello.py')
      >>>> ^D[/color][/color]
      > max@oxygen:~/tmp% ls hello.py*
      > hello.py hello.pyc
      > max@oxygen:~/tmp% rm hello.py
      > max@oxygen:~/tmp% python hello.pyc
      > Hello, world![/color]

      Can I run these scripts under another UID than the user executing them?
      (SUID)

      Thx,
      Florian

      Comment

      • Jeff Epler

        #4
        Re: Problems compiling python

        see Misc/setuid-prog.c in the Python source distribution.

        Jeff

        Comment

        Working...