Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run Python scripts with a shebang on Ubuntu. When I create a python script

    #! /usr/bin/env python
    import sys

... and run it I get a shell error:

    root@host:/home/user# ./
    : No such file or directory

How can I make it work?

Solution: Remove '\r's from line endings with dos2unix.

share|improve this question
up vote 11 down vote accepted

I assume the script is executable? Also, check for carriage returns -- maybe windows got its dirty little hands on it? You can check this with 'cat -vE' and look for '\r'.

share|improve this answer

You probably have windows line endings on your file. Please try running dos2unix on it.

share|improve this answer
Yes, it was line endings, I used vi, I'm sure dos2unix would work too. – Alex May 22 '09 at 15:11

Try removing the space between #! and /usr/bin/env, though I don't get why that would work when not importing packages...

share|improve this answer
You are right, I checked, it also does not work when not importing. – Alex May 22 '09 at 14:11
It also won't start with no space. – Alex May 22 '09 at 14:21

Are you sure that the error is happening for the reason you think? Or are you (later in the script) trying to open a file? Start with the simplest case to get things working...

#!/usr/bin/env python
print "Hello, world"


$ chmod +x
$ ./
Hello, world
share|improve this answer

Use the below one liners to remove the new line characters.

perl -e 's/\r//g' -w -p -i


sed -e "s/^M//" >

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.