First program

Peter Otten __peter__ at web.de
Sat Jun 12 05:16:03 EDT 2010


Phil H wrote:

> Hi,
> Trying my hand with Python but have had a small hiccup.
> Reading  'A byte of Python' and created helloworld.py as directed.
> 
> #!/usr/bin/python
> # filename : helloworld.py
> print 'Hello World'
> 
> At the terminal prompt cd to the file location and run from the prompt.
> 
> phil at grumpy:~/projects/python$ python helloworld.py
> Hello World
> 
> All fine.
> 
> Then I tried the following as described in the tutorial and get the
> following error
> 
> phil at grumpy:~/projects/python$ chmod a+x helloworld.py
> phil at grumpy:~/projects/python$ ./helloworld.py
> bash: ./helloworld.py: /usr/bin/python^M: bad interpreter: No such file
> or directory
> 
> The permissions are: rwxr-xr-x.
> 
> Any help appreciated
> Phil

Did you write your script on a windows machine? Your line endings seem to be 
\r\n but you need \n. You can use dos2unix to fix the line endings:


$ cat -v tmp.py
#!/usr/bin/python^M
print 'hello world'^M
$ ./tmp.py
bash: ./tmp.py: /usr/bin/python^M: bad interpreter: No such file or 
directory
$ dos2unix tmp.py
$ cat -v tmp.py
#!/usr/bin/python
print 'hello world'
$ ./tmp.py
hello world
$

Peter



More information about the Python-list mailing list