You are not logged in.

#1 2014-02-25 15:02:50

dreadz
Member
Registered: 2011-11-23
Posts: 27

[SOLVED]Python script keeps getting SyntaxError: invalid syntax

Hi, i am trying to run a python script, but every time i try to run it

with ./unlocker.py i get

File "./unlocker.py", line 31
    print 80 * "*"
           ^
SyntaxError: invalid syntax

dreadz ~ >  which python
/usr/bin/python

I have consulted with the wiki, and attempted all solutions there

to deal with the enviroment problems. If i use virtualenv2 i get this

Traceback (most recent call last):
  File "./unlocker.py", line 27, in <module>
    import time, serial, re, hashlib, glob
ImportError: No module named serial

(venv)dreadz ~/builds >  which python
/home/dreadz/builds/venv/bin/python
(venv)dreadz ~/builds >

The script runs on a solaris system but not on mine.

Maybe someone can point me to a solution ?

dreadz ~/builds >  uname -a
Linux ufoo 3.13.5-1-ARCH #1 SMP PREEMPT Sun Feb 23 00:25:24 CET 2014 x86_64 GNU/Linux

Thanks

Last edited by dreadz (2014-02-28 10:04:08)

Offline

#2 2014-02-25 15:08:22

mrunion
Member
From: Jonesborough, TN
Registered: 2007-01-26
Posts: 1,938
Website

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

Are you running Python2 on one system and Python3 on another?


Matt

"It is very difficult to educate the educated."

Offline

#3 2014-02-25 15:24:29

dreadz
Member
Registered: 2011-11-23
Posts: 27

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

The solaris system is in the uni, so i don't know

what version of python is running there.

That's what i have on mine

dreadz ~/builds >  python --version
Python 3.3.4

Offline

#4 2014-02-25 15:32:47

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

dreadz wrote:

The solaris system is in the uni, so i don't know

The version of Python on Solaris is almost certainly Python 2.

print 80 * "*"

This is correct syntax for Python 2.

This is NOT correct syntax for Python 3. In Python 3, "print" is a function.

Offline

#5 2014-02-25 15:56:47

dreadz
Member
Registered: 2011-11-23
Posts: 27

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

If i change the shebang line to:

#!/usr/bin/env python2

i get the Traceback error.

If i run with

python2 script.py

i get the same error.

Offline

#6 2014-02-25 15:59:48

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,041

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

dreadz wrote:

If i change the shebang line to:

#!/usr/bin/env python2

i get the Traceback error.

If i run with

python2 script.py

i get the same error.

Traceback (most recent call last):
  File "./unlocker.py", line 27, in <module>
    import time, serial, re, hashlib, glob
ImportError: No module named serial

The error is extremely descriptive.  Read it again. What is it telling you? What might that mean? What would be the most reasonable solution?

Last edited by jakobcreutzfeldt (2014-02-25 16:02:51)

Offline

#7 2014-02-25 19:05:46

dreadz
Member
Registered: 2011-11-23
Posts: 27

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

jakobcreutzfeldt wrote:

The error is extremely descriptive.  Read it again. What is it telling you? What might that mean? What would be the most reasonable solution?

I don't mean to be dissrespecting but i have read the error and it is not descriptive to me.

I don't have experience with python, i am only trying to run a script that i know for a fact can

run on another system. I know it is something to do with my env path and the solutions to simmilar

problem described in the wiki do not work on my system.

Offline

#8 2014-02-25 19:09:59

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,411

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

"ImportError: No module named serial" is pretty clear, you don't have the serial module installed.

Offline

#9 2014-02-25 19:11:44

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

dreadz wrote:
python2 script.py
Traceback (most recent call last):
  File "./unlocker.py", line 27, in <module>
    import time, serial, re, hashlib, glob
ImportError: No module named serial

"No module name serial" means there is no module named "serial".

If you want to use a module named "serial" then you will need to install a module named "serial". Keep in mind that the module will need to be installed for Python 2.

Offline

#10 2014-02-25 19:53:38

dreadz
Member
Registered: 2011-11-23
Posts: 27

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

drcouzelis wrote:

"No module name serial" means there is no module named "serial".

If you want to use a module named "serial" then you will need to install a module named "serial". Keep in mind that the module will need to be installed for Python 2.

Thanks for pointing this out. I have installed python2-pyserial and now i can run the script.

Thanks for your patience and advice!

Offline

#11 2014-02-25 20:24:12

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED]Python script keeps getting SyntaxError: invalid syntax

You're welcome. smile You can add "[SOLVED]" to the title of this thread by editing your original post.

Yeah, even after all this time Arch Linux is STILL one of the only distributions that switched to Python 3 as the default version. Tricky Arch Linux. Keeps me on my toes. tongue

Offline

Board footer

Powered by FluxBB