Trouble executing pyc files in ubuntu server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RawMustard
    New Member
    • Aug 2007
    • 4

    Trouble executing pyc files in ubuntu server

    Hi Folks, my first post here. Sorry to start with a request.

    I'm having trouble executing python scripts compiled to byte code on ubuntu feisty server version. Basically I can type ./MyScript.py and the script runs fine but if I compile the script and type ./MyScript.pyc it won't run, I just get some junk characters printed to my terminal that mean nothing.

    Now if I type python MyScript.pyc it runs fine. I guess it's a path thing, but I'm not too sure how to solve it.

    Silly thing is, on my feisty workstation all works as expected.

    Anyone have any ideas how I might fix this problem.
  • varuns
    New Member
    • Jun 2007
    • 39

    #2
    Originally posted by RawMustard
    Hi Folks, my first post here. Sorry to start with a request.

    I'm having trouble executing python scripts compiled to byte code on ubuntu feisty server version. Basically I can type ./MyScript.py and the script runs fine but if I compile the script and type ./MyScript.pyc it won't run, I just get some junk characters printed to my terminal that mean nothing.

    Now if I type python MyScript.pyc it runs fine. I guess it's a path thing, but I'm not too sure how to solve it.

    Silly thing is, on my feisty workstation all works as expected.

    Anyone have any ideas how I might fix this problem.
    hi
    try changing permission of the .pyc file using
    Code:
    sudo chmod +x MyScript.pyc
    and also first line of the script should be
    !#/usr/bin/env python

    Comment

    • RawMustard
      New Member
      • Aug 2007
      • 4

      #3
      Originally posted by varuns
      hi
      try changing permission of the .pyc file using
      Code:
      sudo chmod +x MyScript.pyc
      and also first line of the script should be
      !#/usr/bin/env python
      Hey thanks for the reply.

      Yeah I've done all that, the file executes but not correctly for some reason :(
      This is stupid, it works perfectly on 3 other machines but not this one. Fresh install and all :( I even tried compiling on another machine where it works and copying it over but still no go :(

      Comment

      • varuns
        New Member
        • Jun 2007
        • 39

        #4
        Originally posted by RawMustard
        Hey thanks for the reply.

        Yeah I've done all that, the file executes but not correctly for some reason :(
        This is stupid, it works perfectly on 3 other machines but not this one. Fresh install and all :( I even tried compiling on another machine where it works and copying it over but still no go :(
        how r u compiling your script. May be there lies a problem?
        I tried this compile.py script

        Code:
        !#/usr/bin/env python
        import py_compile
        py_compile.compile("MyScript.py")
        and than changed the permission and it worked

        Comment

        • RawMustard
          New Member
          • Aug 2007
          • 4

          #5
          Originally posted by varuns
          how r u compiling your script. May be there lies a problem?
          I tried this compile.py script

          Code:
          !#/usr/bin/env python
          import py_compile
          py_compile.compile("MyScript.py")
          and than changed the permission and it worked
          Yeah that how I did it, just from a console though I didn't write a script to do it.

          I do $ python
          >>> import py_compile
          >>> py_compile.comp ile('libhmi_sys .py')

          Then I chmod +x libhmi_sys.pyc

          then I try and run it with ./libhmi_sys.pyc

          and get:
          Code:
          root@tilsan1-hmi:/opt/tilsan/hmi# ./libhmi_sys.pyc
          : command not foundine 1: 
          ./libhmi_sys.pyc: line 2: {+Fc: command not found
          ./libhmi_sys.pyc: line 3: dZ
                                      Z
                                       d: command not found
          ./libhmi_sys.pyc: line 4: syntax error near unexpected token `('
          ./libhmi_sys.pyc: line 4: `Zd
                                        jo;eiie   Zedjoeie       nend
          djo1eideendjp eideiie       Zedjoeie       neiie        joeid
                                                                Zeidedjo4djo
          ndjo                                                               e
               eqqedjoreideide
                                  dZeiie
                                         ZedjoAedjo4djo
          ndjo                                         e
               eqqedjowedjojeide
                                   eide  eideiie       Zedjoeie       neqedjoYeideideiie Zedjoeie       neqqnedS(iNt:iis/opt/tilsan/hmi/tmp/extInput.jss/opt/tilsan/hmi/hmi_db/s /media/TILSAN-USB/4roller-backups     /dev/sdb1cCs
                                                                                      tidttidtidttidtittidtdtidtidttd      tidtid'
          ^[[?1;2c^[[?1;2croot@tilsan1-hmi:/opt/tilsan/hmi# 1;2c1;2c
          bash: 1: command not found
          bash: 2c1: command not found
          bash: 2c: command not found
          Does that mean anything to you's guys?

          Like I said, on my workstation doing the exact same routine it all works fine :(

          Comment

          • varuns
            New Member
            • Jun 2007
            • 39

            #6
            Originally posted by RawMustard
            Yeah that how I did it, just from a console though I didn't write a script to do it.

            I do $ python
            >>> import py_compile
            >>> py_compile.comp ile('libhmi_sys .py')

            Then I chmod +x libhmi_sys.pyc

            then I try and run it with ./libhmi_sys.pyc

            and get:
            Code:
            root@tilsan1-hmi:/opt/tilsan/hmi# ./libhmi_sys.pyc
            : command not foundine 1: 
            ./libhmi_sys.pyc: line 2: {+Fc: command not found
            ./libhmi_sys.pyc: line 3: dZ
                                        Z
                                         d: command not found
            ./libhmi_sys.pyc: line 4: syntax error near unexpected token `('
            ./libhmi_sys.pyc: line 4: `Zd
                                          jo;eiie   Zedjoeie       nend
            djo1eideendjp eideiie       Zedjoeie       neiie        joeid
                                                                  Zeidedjo4djo
            ndjo                                                               e
                 eqqedjoreideide
                                    dZeiie
                                           ZedjoAedjo4djo
            ndjo                                         e
                 eqqedjowedjojeide
                                     eide  eideiie       Zedjoeie       neqedjoYeideideiie Zedjoeie       neqqnedS(iNt:iis/opt/tilsan/hmi/tmp/extInput.jss/opt/tilsan/hmi/hmi_db/s /media/TILSAN-USB/4roller-backups     /dev/sdb1cCs
                                                                                        tidttidtidttidtittidtdtidtidttd      tidtid'
            ^[[?1;2c^[[?1;2croot@tilsan1-hmi:/opt/tilsan/hmi# 1;2c1;2c
            bash: 1: command not found
            bash: 2c1: command not found
            bash: 2c: command not found
            Does that mean anything to you's guys?

            Like I said, on my workstation doing the exact same routine it all works fine :(
            this is really weired, i have no idea about this, may be someone will post a solution or you can post the solution before anyone does.

            Comment

            • RawMustard
              New Member
              • Aug 2007
              • 4

              #7
              Yep seems no one know what's going on. I suspect ubuntu server version of python is borked. It works on any of their other releases, live cd, desktop xubuntu, just doesn't work on their server version.

              It's actually not compiling the scripts properly for some reason, because if I compile a script on the server and move the pyc file to my workstation it won't run, yet compiling the same script on my workstation works fine on my workstation but won't run on the server.

              Comment

              • foo123
                New Member
                • Nov 2008
                • 1

                #8
                This is because you need to install the binfmt-support package - from the package description, it "allows system administrators to register interpreters for
                various binary formats based on a magic number or their file extension, and
                cause the appropriate interpreter to be invoked whenever a matching file is
                executed".

                I had this python problem too, and this fixed it for me :-)

                Comment

                Working...