Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A quickie: python, terminal "print command not found"

Been using terminal to run python scripts written in textwrangler for about 18 months. Decided to look at possibility of moving to an IDE so downloaded a couple of trial versions. Just downloaded BBEedit and suddenly having problems executing script, either from BBedit or Textwrangler. The following code:

print "Please work"

for i in range(50):
    print i

yields the following error message:

/Users/paulpatterson/Documents/Python/Scripts/t.py: line 1: print: command not found
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: syntax error near unexpected token `('
/Users/paulpatterson/Documents/Python/Scripts/t.py: line 3: `for i in range(50):'

Some files still work okay, but I'm struggling to figure out why others now aren't - not even sure if BBedit download has caused the problem. Can anyone help?

like image 244
Paul Patterson Avatar asked Nov 30 '10 15:11

Paul Patterson


2 Answers

Try putting

#!/usr/bin/env python

at the top of the script. The program is trying to execute it like a shell script instead of running it through python.

like image 63
unutbu Avatar answered Oct 12 '22 23:10

unutbu


It's running the script as a shell script, not a Python script.

like image 26
Ignacio Vazquez-Abrams Avatar answered Oct 13 '22 00:10

Ignacio Vazquez-Abrams