bash 运行 Django ./manage.py 时出现错误“没有这样的文件或目录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12252198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error "No such file or directory" when running Django ./manage.py
提问by msampaio
In my djangoproject, 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 syncdband 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:
我的管理.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. 我该如何解决这个问题manage.py [command]?
回答by Octopus
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 连接时,就会发生这种情况。
回答by Martijn Pieters
The #!hash-bang line doesn't point to your virtualenv python; replace the first line with:
该#!散列砰线并不指向你的virtualenv蟒蛇; 将第一行替换为:
#!/path/to/virtualenv/bin/python
回答by LSerni
In my django project, the command ./manage.py [command] results in this error message:
: No such file or directory
The command python manage.py [command] works well
在我的 django 项目中,命令 ./manage.py [command] 导致此错误消息:
: 无此文件或目录
命令 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).
(或口译员所在的任何地方。用: 找到它which python)。
回答by alxs
In my case, I was erroneously changing the sys.pathin my manage.py.
就我而言,我错误地改变了sys.path我manage.py。
回答by Zompa
In my case on Windows 7, every else it seems to be, but I've accidentally added an import in a views.py file:
就我在 Windows 7 上的情况而言,其他一切似乎都是如此,但我不小心在 views.py 文件中添加了一个导入:
from Scripts.pilprint import description
My software doesn't need this import, maybe with some wrong short-kut, my Eclipse wrote it for me, but removed this line, the problem disappear.
我的软件不需要这个导入,也许有一些错误的short-kut,我的Eclipse为我写了它,但删除了这一行,问题就消失了。
I suppose that description contain some painful character or have a wrong encoding for Windows.
我想该描述包含一些令人痛苦的字符或 Windows 的编码错误。

