我正在尝试在Django中开发示例项目,并且在运行syncdb命令时遇到错误。
这是我的项目结构的样子:
/ Users / django_demo / godjango / bookings:
manage.py
registration/
forms.py
views.py
models.py
urls.py
bookings/
settings.py
urls.py
我的manage.py文件如下:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我的PYTHONPATH和DJANGO_SETTINGS_MODULE设置如下
$echo $DJANGO_SETTINGS_MODULE
bookings.settings
$ echo $PYTHONPATH
/Users/django_demo/godjango/bookings
我的WSGI.py文件如下所示:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
当我运行python manage.py syncdb命令时,出现以下错误。
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'bookings.settings' (Is it on sys.path?): No module named unipath
有人可以建议我缺少什么吗?
错误说 ImportError: Could not import settings 'bookings.settings' (Is it on sys.path?): No module named unipath
那么,你的路径是否/Users/django_demo/godjango/bookings
在python-sys.path
中?
使用以下命令在你的外壳中检查它:
$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for path in sys.path: print path
...
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/spyne-2.8.2_rc-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-3.0alpha2-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2012d-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_debug_toolbar-0.9.4-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_social_auth-0.7.7-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4.1-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2-0.7.6-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Python/2.7/site-packages
>>>
如果不是-你需要添加它或将你的bookings
应用程序移动到你所表示的路径之一中sys.path
问题内容: 我已经在pycharm中配置了virtualenv,当使用python manage.py命令时,显示错误: 我应该如何解决,我已经安装了django。 问题答案: 我认为使用django的最佳方法是使用virtualenv,它是安全的,你可以在virtualenv中安装许多应用程序,而这不会影响系统的任何外部空间。vitualenv使用python的默认版本,与在系统中安装virtu
问题内容: 我有两个文件, app.py mod_login.py 而python返回此错误: 如果删除from app import app,代码将起作用,但是如何访问? 问题答案: 问题是你有一个循环导入:在app.py中 在mod_login.py中 这在Python中是不允许的。有关更多信息,请参见Python中的循环导入依赖项。简而言之,解决方案是 要么将所有内容收集到一个大文件中 使用
问题内容: 我正在尝试运行以下简单代码 但我收到以下错误 我正在Windows 10下使用python 2.7。 我已经安装了,但是似乎无法解决问题 任何帮助表示赞赏。 问题答案: 如果查看引起错误的行,则会看到以下内容: 该行注释将依赖项声明为(对于 Intel Math Kernel Library )。这意味着您已经安装了by ,但是the是由预编译的存档安装的,其期望值为。 通过从此处的w
问题内容: 我没有找到解决方案,有人可以帮忙吗? 问题答案: 1. 尝试更新 2. 尝试重新安装 以下代码段将打印到控制台什么?
问题内容: 我正在尝试使用ttk模块为tkinter中的GUI应用程序为Windows创建可执行文件。我使用cx_freeze制作了一个exe,但是当我在控制台中运行该应用程序时,出现以下错误: 这是我的代码中的第14和15行: 问题答案: 看起来cx_freeze没有意识到它应该包含该模块,该模块有条件地由导入。您可以告诉它在命令行参数或关键字参数to中明确包含该模块。
问题内容: 我无法使ffprobe软件包在Python 3.6中工作。我使用pip安装了它,但是当我输入时说 init.py文件仅包含一行。 包括“ C:\ Python \ Python36 \ lib \ site-packages”,这是ffprobe目录所在的位置。 安装和导入软件包在Python 2.7中都可以正常工作。但是我想在Python 3中使用它,即使这意味着对.py文件进行手动