简体   繁体   English

Django manage.py问题

[英]Django manage.py question

Why is it that I have to run python manage.py somecommand and others simply run manage.py somecommand ? 为什么我必须运行python manage.py somecommand而其他人只需运行manage.py somecommand I'm on OSX 10.6. 我在OSX 10.6上。 Is this because there is a pre-set way to enable .py files to automatically run as Python scripts, and I've somehow disabled the functionality, or is that something that you explicitly enable? 这是因为有一种预先设定的方法可以使.py文件自动作为Python脚本运行,而且我已经以某种方式禁用了这些功能,或者是你明确启用的东西?

If you are using a recent version of Django, the manage.py file should be an "executable" file by default. 如果您使用的是最新版本的Django,则manage.py文件默认情况下应为“可执行”文件。

Please note, you cannot just type manage.py somecommand into the terminal as manage.py is not on the PATH, you will have to type ./ before it to run it from the current directory, ie ./manage.py somecommand . 请注意,您不能只将manage.py somecommand键入到终端中,因为manage.py不在PATH上,您必须在它之前键入./才能从当前目录运行它,即./manage.py somecommand

If that does not work please be sure that the manage.py file has: #!/usr/bin/env python as its first line. 如果这不起作用,请确保manage.py文件具有: #!/usr/bin/env python作为其第一行。 And make sure it is executable: chmod +x manage.py 并确保它是可执行的: chmod +x manage.py

There are two things you should look at: 你应该看两件事:

First, is the manage.py script set to be executable? 首先,manage.py脚本是否可执行? If not, try 如果没有,试试吧

chmod u+x manage.py

Secondly, does manage.py have a valid hashbang line? 其次,manage.py有一个有效的hashbang行吗? If not, you could try adding one that points to the correct python interpreter for your system. 如果没有,您可以尝试添加一个指向您系统的正确python解释器。

On the mac the manage.py command has to be executable to just run it without the python command. 在mac上,manage.py命令必须是可执行的,只需在没有python命令的情况下运行它。 You can do this with: 你可以这样做:

chmod 755 manage.py

If you are in the same directory as manage.py, to run it you type: 如果您与manage.py位于同一目录中,要运行它,请键入:

./manage.py somecommand

Otherwise you want to specify the path: 否则你想指定路径:

/path/to/my/project/manage.py somecommand

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM