471,338 Members | 1,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

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.
Aug 16 '07 #1
7 6472
varuns
39
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
Expand|Select|Wrap|Line Numbers
  1. sudo chmod +x MyScript.pyc
and also first line of the script should be
!#/usr/bin/env python
Aug 16 '07 #2
hi
try changing permission of the .pyc file using
Expand|Select|Wrap|Line Numbers
  1. 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 :(
Aug 16 '07 #3
varuns
39
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

Expand|Select|Wrap|Line Numbers
  1. !#/usr/bin/env python
  2. import py_compile
  3. py_compile.compile("MyScript.py")
and than changed the permission and it worked
Aug 16 '07 #4
how r u compiling your script. May be there lies a problem?
I tried this compile.py script

Expand|Select|Wrap|Line Numbers
  1. !#/usr/bin/env python
  2. import py_compile
  3. 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.compile('libhmi_sys.py')

Then I chmod +x libhmi_sys.pyc

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

and get:
Expand|Select|Wrap|Line Numbers
  1. root@tilsan1-hmi:/opt/tilsan/hmi# ./libhmi_sys.pyc
  2. : command not foundine 1: 
  3. ./libhmi_sys.pyc: line 2: {+Fc: command not found
  4. ./libhmi_sys.pyc: line 3: dZ
  5.                             Z
  6.                              d: command not found
  7. ./libhmi_sys.pyc: line 4: syntax error near unexpected token `('
  8. ./libhmi_sys.pyc: line 4: `Zd
  9.                               jo;eiie   Zedjoeie       nend
  10. djo1eideendjp eideiie       Zedjoeie       neiie        joeid
  11.                                                       Zeidedjo4djo
  12. ndjo                                                               e
  13.      eqqedjoreideide
  14.                         dZeiie
  15.                                ZedjoAedjo4djo
  16. ndjo                                         e
  17.      eqqedjowedjojeide
  18.                          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
  19.                                                                             tidttidtidttidtittidtdtidtidttd      tidtid'
  20. ^[[?1;2c^[[?1;2croot@tilsan1-hmi:/opt/tilsan/hmi# 1;2c1;2c
  21. bash: 1: command not found
  22. bash: 2c1: command not found
  23. bash: 2c: command not found
  24.  
Does that mean anything to you's guys?

Like I said, on my workstation doing the exact same routine it all works fine :(
Aug 16 '07 #5
varuns
39
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.compile('libhmi_sys.py')

Then I chmod +x libhmi_sys.pyc

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

and get:
Expand|Select|Wrap|Line Numbers
  1. root@tilsan1-hmi:/opt/tilsan/hmi# ./libhmi_sys.pyc
  2. : command not foundine 1: 
  3. ./libhmi_sys.pyc: line 2: {+Fc: command not found
  4. ./libhmi_sys.pyc: line 3: dZ
  5.                             Z
  6.                              d: command not found
  7. ./libhmi_sys.pyc: line 4: syntax error near unexpected token `('
  8. ./libhmi_sys.pyc: line 4: `Zd
  9.                               jo;eiie   Zedjoeie       nend
  10. djo1eideendjp eideiie       Zedjoeie       neiie        joeid
  11.                                                       Zeidedjo4djo
  12. ndjo                                                               e
  13.      eqqedjoreideide
  14.                         dZeiie
  15.                                ZedjoAedjo4djo
  16. ndjo                                         e
  17.      eqqedjowedjojeide
  18.                          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
  19.                                                                             tidttidtidttidtittidtdtidtidttd      tidtid'
  20. ^[[?1;2c^[[?1;2croot@tilsan1-hmi:/opt/tilsan/hmi# 1;2c1;2c
  21. bash: 1: command not found
  22. bash: 2c1: command not found
  23. bash: 2c: command not found
  24.  
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.
Aug 17 '07 #6
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.
Aug 18 '07 #7
foo123
1
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 :-)
Nov 11 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by bg_ie | last post: by
11 posts views Thread by dave6502 | last post: by
4 posts views Thread by per9000 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.