无法使用django-admin.py

时间:2012-06-20 04:23:47

标签: django

我是Django的新手,并试图创建我的第一个项目。我知道我需要运行命令“python django-admin.py startproject iFriends”(iFriends是我为项目创建的文件夹)。终端正在响应 - “-bash:django-admin.py:command not found。”为什么不起作用?这是错误的命令吗?

我使用的是Mac OS X 10.7.3,Django 1.4和Python 2.7.2。

4 个答案:

答案 0 :(得分:1)

我也在Mac OS 10.7.x上使用Python 2.7(使用Django 1.5.1)。我认为这个教程已经过时了。尝试使用“django-admin-2.7.py”命令而不仅仅是“django-admin.py”,其他一切都相同。经过一个多小时的调查PATHS和符号链接等,这个解决方案对我有用。

这是我所遵循的蜿蜒道路,如果你想为后代而受苦:

python -c“import sys; sys.path = sys.path [1:]; import django; print(django。 path )”

  • Mine返回了以下路径,与文档非常不同:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin

  • 我开始遵循符号链接建议,但是当我尝试创建符号链接到/ usr / local / bin时,我无法做到(主题是另一篇文章)。
  • 在查看$ PATH($ echo $PATH)后,我想查看/ opt / local / bin而不是usr / local / bin。而且,有一个名为django-admin-2.7.py的文件。难道我只需要在教程中将命令版本号添加到命令中吗?
  • 我导航回我的Code文件夹,在那里我将放置我的Django项目,并按照教程(https://docs.djangoproject.com/en/1.5/intro/tutorial01/)设置新项目。但是我尝试django-admin.py而不是django-admin-2.7.py。它奏效了!

答案 1 :(得分:0)

你的系统路径上有django-admin.py吗?结帐:https://code.djangoproject.com/wiki/InstallationPitfalls

答案 2 :(得分:0)

如果您正在使用Windows并需要更新系统路径,请确保在再次尝试之前关闭并重新打开命令提示符。我遇到了类似的问题,这就是为我解决的问题。

答案 3 :(得分:0)

作为一种解决方法,请运行Python

/*
 * Opens the process `cmd` similar to popen() but does not invoke a shell.
 * Instead, wordexp() is used to expand the given command, if necessary.
 * If successful, the process id of the new process is being returned and the 
 * given FILE pointers are set to streams that correspond to pipes for reading 
 * and writing to the child process, accordingly. Hand in NULL for pipes that
 * should not be used. On error, -1 is returned.
 */
pid_t popen_noshell(const char *cmd, FILE **out, FILE **err, FILE **in)
{
    if (!cmd || !strlen(cmd)) return -1;

    // 0 = read end of pipes, 1 = write end of pipes
    int pipe_stdout[2];
    int pipe_stderr[2];
    int pipe_stdin[2];

    if (out && (pipe(pipe_stdout) < 0)) return -1;
    if (err && (pipe(pipe_stderr) < 0)) return -1;
    if (in  && (pipe(pipe_stdin)  < 0)) return -1;

    pid_t pid = fork();
    if (pid == -1)
    {
        return -1;
    }
    else if (pid == 0) // child
    {    
        // redirect stdout to the write end of this pipe
        if (out)
        {
            if (dup2(pipe_stdout[1], STDOUT_FILENO) == -1) return -1;
            close(pipe_stdout[0]); // child doesn't need read end
        }
        // redirect stderr to the write end of this pipe
        if (err)
        {
            if (dup2(pipe_stderr[1], STDERR_FILENO) == -1) return -1;
            close(pipe_stderr[0]); // child doesn't need read end
        }
        // redirect stdin to the read end of this pipe
        if (in)
        {
            if (dup2(pipe_stdin[0], STDIN_FILENO) == -1) return -1;
            close(pipe_stdin[1]); // child doesn't need write end
        }

        wordexp_t p;
        if (wordexp(cmd, &p, 0) != 0) return -1;

        execvp(p.we_wordv[0], p.we_wordv);
        _exit(1);
    }
    else // parent
    {
        if (out)
        {
            close(pipe_stdout[1]); // parent doesn't need write end
            *out = fdopen(pipe_stdout[0], "r");
        }
        if (err)
        {
            close(pipe_stderr[1]); // parent doesn't need write end
            *err = fdopen(pipe_stderr[0], "r");
        }
        if (in)
        {
            close(pipe_stdin[0]); // parent doesn't need read end
            *in = fdopen(pipe_stdin[1], "w");
        }
        return pid;
    }
}

django-admin 替换为 python(您的站点软件包地址)/django/bin/django-admin.py < / em>

启动项目的完整示例:

Error: Serverless-offline: handler for 'hello' is not a function
    at Object.createHandler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/functionHelper.js:221:11)
    at handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/serverless-offline/src/ApiGateway.js:485:40)
    at module.exports.internals.Manager.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/toolkit.js:41:33)
    at Object.internals.handler (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:46:48)
    at exports.execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/handler.js:31:36)
    at Request._lifecycle (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:312:68)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Request._execute (/home/savnik/serverless-webpack-typescript-apollo/node_modules/@hapi/hapi/lib/request.js:221:9)