Python Script Runs Only With The "python" Command
Solution 1:
Your file has carriage returns in it. Did you write it in a Windows text editor?
Try running dos2unix manage.py manage.py
Solution 2:
glenn jackman's answer is correct, but I don't have enough "reputation" to upvote him, so I'll post this here. Your script is in Windows format, in which every line ends with a carriage return and linefeed, instead of just a linefeed. Many programs, including python, can handle either format with no problem. But when you run the script, the shell believes that the carriage return is part of the command name. Instead of running "/usr/bin/env python", your shell is trying to run "/usr/bin/env python^M" (where ^M is a linefeed). You can tell this is the case because of the error message it gives you. Just before "No such file or directory", it prints the name of the program it tried to execute. It printed the linefeed too, which moved the cursor back to the leftmost position in the line, which erased everything before the colon.
If you don't have dos2unix installed, you can remove the linefeeds with
tr -d '\r' < manage.py > manage2.py; mv manage2.py manage.py
You can't read from and write to the same file at the same time, which is why you have to use a temporary file to hold the output of tr
.
Solution 3:
I suspect that the shebang at the top of the file is incorrect. The file should start with either:
#!/usr/bin/python
(where the python path is the output of which python
)
or
#!/usr/bin/env python
Solution 4:
If the permissions are 766
and you're not the owner, you don't have permission to execute it. 6
means you can read and write but not execute. It's unusual for a system file like that to be world-writeable; normally it would be 755
. If you have rootly powers, use chmod 755 manage.py
to fix it.
Solution 5:
When you run a script directly, the script is started with the interpreter specified in the first line:
#!COMMAND
Where COMMAND is /bin/bash for shell scripts. For python, it's best to use
#!/usr/bin/env python
So that the version of python from the environment is selected.
Post a Comment for "Python Script Runs Only With The "python" Command"