简体   繁体   中英

Script works on Windows, but not on Linux (Syntax Error)

I created a python script on my PC (Windows 10) with Python 3.6.2 and it works like a charm :

for i in range(101):
    time.sleep(0.015)
    print('Starting ..... [%d%%]\r'%i, end="")
else :
   print('\n Ready.')

I recently got a raspberry pi running on raspbian with Python 3.4.2 and when I try to run the exact same script from the command I got an error:

print('Starting ..... [%d%%]\r'%i, end="")
                                      ^
Syntax Error: invalid Syntax (The error seems to be the equal sign)

Any idea? Maybe Python version? Maybe something else?

EDIT :

Indeed, @Steven Rumbalski is right. Raspbian automaticaly install 2 versions of Python : 2.7.9 and 3.4.2 So I just had to put "python3 myscript.py" instead of "python myscript.py" (or, as @Toandd said : use a shebang line) thank you very much for the help.

I have same idea with @Steven Rumbalski. And to resolve this issue, you should add following line at the top of python script (shebang line).

#!/usr/bin/python3

Or you can run "python3 script.py" if you don't want to add shebang line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM