运行Django ./manage.py时出错“No such file or directory”

时间:2021-12-31 18:04:18

In my django project, the command ./manage.py [command] results in this error message:

在我的django项目中,命令./manage.py [command]会产生以下错误消息:

: No such file or directory

The command python manage.py [command] works well. I tried with syncdb and runserver. I tried chmod a+x manage.py, but the problem persists.

命令python manage.py [command]运行良好。我尝试使用syncdb和runserver。我试过chmod a + x manage.py,但问题仍然存在。

My manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

I use django 1.4.1 in a virtualenv. How can I fix this to use manage.py [command]?

我在virtualenv中使用django 1.4.1。如何修复此问题以使用manage.py [command]?

4 个解决方案

#1


9  

Likely, the reason is because your line endings in the manage.py file are \n instead of \r\n. As a result the #! hash-bang is misinterpreted.

可能原因是因为manage.py文件中的行结尾是\ n而不是\ r \ n。结果#! hash-bang被误解了。

This happens to me when I use a Windows based text-editor for my linux connection.

当我使用基于Windows的文本编辑器进行linux连接时,就会发生这种情况。

#2


3  

The #! hash-bang line doesn't point to your virtualenv python; replace the first line with:

#! hash-bang line并没有指向你的virtualenv python;将第一行替换为:

#!/path/to/virtualenv/bin/python

#3


2  

In my django project, the command ./manage.py [command] results in this error message:

在我的django项目中,命令./manage.py [command]会产生以下错误消息:

: No such file or directory

: 无此文件或目录

The command python manage.py [command] works well

命令python manage.py [command]运行良好

If specifying the interpreter makes it work, then it is the first line that must be wrong:

如果指定解释器使其工作,那么它是第一行必须是错误的:

#!/usr/bin/env python

Try:

#!/usr/bin/python

(or wherever the interpreter is. Find it with: which python).

(或者解释器所在的位置。找到它:哪个python)。

#4


1  

In my case, I was erroneously changing the sys.path in my manage.py.

就我而言,我错误地更改了manage.py中的sys.path。

#1


9  

Likely, the reason is because your line endings in the manage.py file are \n instead of \r\n. As a result the #! hash-bang is misinterpreted.

可能原因是因为manage.py文件中的行结尾是\ n而不是\ r \ n。结果#! hash-bang被误解了。

This happens to me when I use a Windows based text-editor for my linux connection.

当我使用基于Windows的文本编辑器进行linux连接时,就会发生这种情况。

#2


3  

The #! hash-bang line doesn't point to your virtualenv python; replace the first line with:

#! hash-bang line并没有指向你的virtualenv python;将第一行替换为:

#!/path/to/virtualenv/bin/python

#3


2  

In my django project, the command ./manage.py [command] results in this error message:

在我的django项目中,命令./manage.py [command]会产生以下错误消息:

: No such file or directory

: 无此文件或目录

The command python manage.py [command] works well

命令python manage.py [command]运行良好

If specifying the interpreter makes it work, then it is the first line that must be wrong:

如果指定解释器使其工作,那么它是第一行必须是错误的:

#!/usr/bin/env python

Try:

#!/usr/bin/python

(or wherever the interpreter is. Find it with: which python).

(或者解释器所在的位置。找到它:哪个python)。

#4


1  

In my case, I was erroneously changing the sys.path in my manage.py.

就我而言,我错误地更改了manage.py中的sys.path。