Django 1.5 b1:执行django-admin。py导致“无模块命名设置”错误。

时间:2021-12-30 20:21:58

I've recently installed Django-1.5b1. My system configuration:

我最近安装django - 1.5 b1。我的系统配置:

  • OSX 10.8
  • OSX 10.8
  • Python 2.7.1
  • Python 2.7.1
  • Virtualenv 1.7.2
  • Virtualenv 1.7.2

When I call django-admin.py command I get the following error

当我叫django-admin。py命令得到以下错误

(devel)ninja Django-1.5b1: django-admin.py 
Usage: django-admin.py subcommand [options] [args]

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Print traceback on exception
  --version             show program's version number and exit
  -h, --help            show this help message and exit
Traceback (most recent call last):
  File "/Users/sultan/.virtualenvs/devel/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 452, in execute_from_command_line
    utility.execute()
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 375, in execute
    sys.stdout.write(self.main_help_text() + '\n')
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 241, in main_help_text
    for name, app in six.iteritems(get_commands()):
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 108, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 52, in __getattr__
    self._setup(name)
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings

Did anyone have the same errors? Can anyone advise or help with it?

有人犯过同样的错误吗?有人能提出建议或提供帮助吗?

Thanks,

谢谢,

Sultan

苏丹

6 个解决方案

#1


24  

I had the same issue when starting a new project. I solved the problem by giving this command at the command prompt:

我在开始一个新项目时也遇到了同样的问题。我通过在命令提示符下发出这个命令来解决这个问题:

export DJANGO_SETTINGS_MODULE=

in this way I unset the variable that was pointing to a "settings" file (discovered using env | grep DJANGO_SETTINGS_MODULE) I set before starting using virtualenv

通过这种方式,我在使用virtualenv之前设置了指向“设置”文件的变量(使用env | grep DJANGO_SETTINGS_MODULE发现)

after unsetting the variable the django-admin.py script worked like a charm!

在解压变量django-admin之后。py脚本工作得很有魅力!

#2


6  

I've had the same issue as you, and I haven't come up with a good fix aside from prepending my project folder to the PYTHONPATH like this:

我和你有同样的问题,我还没有拿出一个好的解决方案,把我的项目文件夹放到PYTHONPATH里,像这样:

export PYTHONPATH="/absolute/path/to/django/project/folder:$PYTHONPATH"

where my <project> is located at /absolute/path/to/django/project/folder/<project>. I add that export command to the end of my env/bin/activate script so it happens every time I initialize the virtualenv.

我的 位于/absolute/path/to/django/project/folder/ 。我将export命令添加到env/bin/activate脚本的末尾,以便每次初始化virtualenv时都能执行。

The only difference between our two situations is that I use multiple settings files instead of a single settings.py module.

这两种情况之间的唯一区别是我使用多个设置文件而不是单个设置。py模块。

You can also call django-admin.py from the folder containing your Django project like so:

你也可以打电话给django-admin。来自包含Django项目的文件夹的py如下:

python ~/.virtualenvs/devel/bin/django-admin.py <command>

so that it recognizes your current working directory as part of the path.

这样它就能将当前工作目录识别为路径的一部分。

Hope that makes sense. It's kind of clumsy to explain which makes it hard to search for an answer.

希望是有意义的。很难解释为什么很难找到答案。

#3


0  

Maybe your problem is related to this: Wrong python path in script header

也许您的问题与此有关:脚本头中的python路径错误

If you want to do anything except creating a new django project inside your venv, you should call python manage.py (of course, whereis python should return your venv executable)

如果除了在venv中创建一个新的django项目之外,您还需要做其他事情,那么应该调用python manage。py(当然,python应该返回您的venv可执行文件)

#4


0  

Don't run the script from the direct path to the django library; run it from any other path. It seems you cd into the directory where django is installed (or where you downloaded and expanded it) and then ran the command from there.

不要从直接路径运行到django库的脚本;从任何其他路径运行它。看起来您将cd存储到安装django的目录(或者下载并展开它的目录),然后从那里运行命令。

So try this:

那么试试这个:

(devel)ninja Django-1.5b1: cd 
(devel)ninja: django-admin.py startproject foo

#5


-1  

Are you sure you are starting the django-admin from the virtualenv django instalation ? Perhaps path/to/virtualenv/bin/django-admin.py

您确定要从virtualenv django安装启动django管理吗?也许virtualenv路径/ / / bin / django-admin.py

#6


-1  

for easy solution you can try

为了简单的解决办法,你可以试试

python .\Scripts\django-admin.py startproject projectname

python。\ \ django-admin的脚本。py startproject projectname

after that run the

在那之后运行

#1


24  

I had the same issue when starting a new project. I solved the problem by giving this command at the command prompt:

我在开始一个新项目时也遇到了同样的问题。我通过在命令提示符下发出这个命令来解决这个问题:

export DJANGO_SETTINGS_MODULE=

in this way I unset the variable that was pointing to a "settings" file (discovered using env | grep DJANGO_SETTINGS_MODULE) I set before starting using virtualenv

通过这种方式,我在使用virtualenv之前设置了指向“设置”文件的变量(使用env | grep DJANGO_SETTINGS_MODULE发现)

after unsetting the variable the django-admin.py script worked like a charm!

在解压变量django-admin之后。py脚本工作得很有魅力!

#2


6  

I've had the same issue as you, and I haven't come up with a good fix aside from prepending my project folder to the PYTHONPATH like this:

我和你有同样的问题,我还没有拿出一个好的解决方案,把我的项目文件夹放到PYTHONPATH里,像这样:

export PYTHONPATH="/absolute/path/to/django/project/folder:$PYTHONPATH"

where my <project> is located at /absolute/path/to/django/project/folder/<project>. I add that export command to the end of my env/bin/activate script so it happens every time I initialize the virtualenv.

我的 位于/absolute/path/to/django/project/folder/ 。我将export命令添加到env/bin/activate脚本的末尾,以便每次初始化virtualenv时都能执行。

The only difference between our two situations is that I use multiple settings files instead of a single settings.py module.

这两种情况之间的唯一区别是我使用多个设置文件而不是单个设置。py模块。

You can also call django-admin.py from the folder containing your Django project like so:

你也可以打电话给django-admin。来自包含Django项目的文件夹的py如下:

python ~/.virtualenvs/devel/bin/django-admin.py <command>

so that it recognizes your current working directory as part of the path.

这样它就能将当前工作目录识别为路径的一部分。

Hope that makes sense. It's kind of clumsy to explain which makes it hard to search for an answer.

希望是有意义的。很难解释为什么很难找到答案。

#3


0  

Maybe your problem is related to this: Wrong python path in script header

也许您的问题与此有关:脚本头中的python路径错误

If you want to do anything except creating a new django project inside your venv, you should call python manage.py (of course, whereis python should return your venv executable)

如果除了在venv中创建一个新的django项目之外,您还需要做其他事情,那么应该调用python manage。py(当然,python应该返回您的venv可执行文件)

#4


0  

Don't run the script from the direct path to the django library; run it from any other path. It seems you cd into the directory where django is installed (or where you downloaded and expanded it) and then ran the command from there.

不要从直接路径运行到django库的脚本;从任何其他路径运行它。看起来您将cd存储到安装django的目录(或者下载并展开它的目录),然后从那里运行命令。

So try this:

那么试试这个:

(devel)ninja Django-1.5b1: cd 
(devel)ninja: django-admin.py startproject foo

#5


-1  

Are you sure you are starting the django-admin from the virtualenv django instalation ? Perhaps path/to/virtualenv/bin/django-admin.py

您确定要从virtualenv django安装启动django管理吗?也许virtualenv路径/ / / bin / django-admin.py

#6


-1  

for easy solution you can try

为了简单的解决办法,你可以试试

python .\Scripts\django-admin.py startproject projectname

python。\ \ django-admin的脚本。py startproject projectname

after that run the

在那之后运行