2012-03-29 101 views
2

我這樣安裝和配置Django/MongoDB!錯誤是:沒有模塊名爲django_mongodb_engine.base

PIP安裝的virtualenv

源的myproject/bin中/激活

PIP安裝汞柱+ HTTPS://bitbucket.org/wkornewald/django-nonrel

PIP安裝汞柱+ HTTPS: //bitbucket.org/wkornewald/djangotoolbox

PIP安裝的git +的https://github.com/django-nonrel/mongodb-engine

所有這些操作都是成功的!

現在,當我改變了settings.py文件像這樣:

DATABASES = { 
    'default': { 
     'ENGINE': 'django_mongodb_engine', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'mong_db',      # Or path to database file if using sqlite3. 
     'USER': '',      # Not used with sqlite3. 
     'PASSWORD': '',     # Not used with sqlite3. 
     'HOST': '',      # Set to empty string for localhost. Not used with sqlite3. 
     'PORT': '',      # Set to empty string for default. Not used with sqlite3. 
    } 

發生的令人費解的錯誤:

Error was: No module named django_mongodb_engine.base 

顯然安裝成功django_mongodb_engine。但爲什麼會出現這個錯誤?

btw,原諒我可憐的英語!

回答

1

我通過你做同樣的步驟去了,再開一個Python外殼:

$ python 
>>> import django_mongodb_engine.base 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django_mongodb_engine/base.py", line 4, in <module> 
    from django.db.backends.signals import connection_created 
    File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module> 
    if not settings.DATABASES: 
    File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__ 
    self._setup() 
    File "/Users/emptysquare/.virtualenvs/foo/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup 
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE) 
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined. 

但是,如果我做的:

$ DJANGO_SETTINGS_MODULE=settings python 
>>> import django_mongodb_engine.base 

...它的工作原理。

您能設置DJANGO_SETTINGS_MODULE並嘗試在Python shell中導入django_mongodb_engine.base嗎?

相關問題