linux - python SyntaxError when trying to import package BUT only when running remotely -
i have following scripts:
test.py:
import sys try: import random print random.random() except: print sys.exc_info()[0]
run.sh:
python "test.py" >> "test_file" ;
when running following command on linux server:
[saray@compute-0-15 ~]$ nohup ./run.sh &
test_file includes random number expected:
[saray@compute-0-15 ~]$ cat test_file 0.923051769631
but, when running same command remotely using:
[saray@blob-cs ~]$ ssh "compute-0-15" 'nohup ./run.sh > /dev/null 2>&1 &'
python fails upload random package!!
[saray@compute-0-15 ~]$ cat test_file exceptions.syntaxerror
what's wrong?
your remote machine running different python version, python 3.
in python 3, print
statement has been replaced print
function, , code throwing syntax error.
the work-around either run code remotely python 2 well, or make code compatible both python 2 , 3:
from __future__ import print_function import sys import random print(random.random())
Comments
Post a Comment