我一直在尝试使用Django,但是当我尝试使用CLI创建最简单的项目时,我一直收到错误:“ImportError:没有名为californication.settings的模块”。据我所知,Python没有名为“californication”的模块,我无法弄清楚为什么Django正在寻找这个模块。我的笔记本电脑上安装了Python 2.7(Macbook Air,运行macOS Sierra 10.12)。
注意:这里没有代码可以显示给你,因为我甚至没有这么做。我只是尝试使用Django工具包自动生成Django项目,如下所述:https://docs.djangoproject.com/en/1.10/intro/tutorial01/
这是我在使用pip安装Django时看到的内容:
$ pip install django
Downloading/unpacking django
Downloading Django-1.10.5.tar.gz (7.7MB): 7.7MB downloaded
Running setup.py egg_info for package django
no previously-included directories found matching 'django/contrib/admin/bin'
warning: no previously-included files matching '__pycache__' found anywhere in distribution
Installing collected packages: django
Running setup.py install for django
no previously-included directories found matching 'django/contrib/admin/bin'
warning: no previously-included files matching '__pycache__' found anywhere in distribution
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /usr/local/bin/django-admin.py to 755
Installing django-admin script to /usr/local/bin
Successfully installed django
Cleaning up...
现在,当我使用django-admin创建项目时,这就是我所看到的:
$ django-admin startproject mysite
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 9, in <module>
load_entry_point('Django==1.10.5', 'console_scripts', 'django-admin')()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named californication.settings
这里的任何想法或帮助将不胜感激。堆栈跟踪似乎指向一些Django配置文件,但正如您在上面所看到的,我刚刚完成了设置Django的最低限度,并且没有修改任何配置文件。
答案 0 :(得分:2)
首先要做的事情是:你不应该在全球范围内安装django。
如果需要,请使用virtualenv(+ virtualenv wrapper。)
其次,请按照以下命令进入shell:
echo $DJANGO_SETTINGS_MODULE
如果返回的话:
unset DJANGO_SETTINGS_MODULE
看起来有些东西是全局设置,也许是其他一些python应用程序或类似的东西。
另外,只是为了确保项目目录中没有剩余的.pyc文件:
find . -name "*.pyc" -delete