[Tutor] hello.py: line 1: print: command not found

Bill Burns billburns at pennswoods.net
Sun Dec 5 08:45:18 CET 2004


On Saturday 04 December 2004 11:53 pm, Cullen Newsom wrote:
> Max,
>
>     Thanks for your reply.  I have already tried to set my
> confirmation that this is not a file permission problem, I
> should say that I can run hello.py as root, and get the expected
> result.  I can also run it as normal user, from /usr/lib/python
> and get the proper behavior.  It is from /home/user/hello.py
> that this error persists.  I included below the attribute flags
> from ls-l.  Thanks again for your help, any ideas are
> appreciated.
>
> Cullen
>
> <file attributes>
> nooseisloose at linux:~> ls -l hello.py
> -rwxrwxrwx  1 nooseisloose users 42 2004-12-04 18:36 hello.py
> </file attributes>
>

Hello Cullen, 

I don't know if this will help solve your problem or not. I thought I would
fool around with it since I also use SUSE 9.1.

As I believe you suspected, as well as Max, your error is coming from the
shell, not python, Bash doesn't know how to execute the code. 

Your file works on my box using either shebang.

I can only replicate your error if I do the following:
1). Completely remove "#!/usr/bin/python" as the first line in the script.
2). Make print "Hello, world!" the first line in the script.
3). Make sure that execute permissions (+x) are set and issue the command
"./hello.py". 

bill at blkbox:~/Desktop> ./hello.py
./hello.py: line 1: print: command not found

Because your error contains "line 1: print:" , it would seem that the print
command is on line one and that your first line does not contain
"#!/usr/bin/python". But your output from "cat" and "print
repr(open('/home/nooseisloose/hello.py', 'rb').read(160))" say that you do
have it at the top of the file. Strange!

I know that there was an updated Bash for our distro a while ago but I have no
idea what the specific problem was. Looking at your kernel version I can see
that's your system is not up to date (at least the kernel anyway), maybe you
need to do an update. I'm currently using bash-2.05b-305.1.

HTH

Bill


More information about the Tutor mailing list