I am in the plain python shell and I am getting this error when trying to import my project models:
from results.models import TestResult  
Traceback (most recent call last):  
  File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in <module>  
    # Used internally for debug sandbox under external interpreter  
  File "C:\Users\audrey_moreau\myProject\results\models.py", line 1, in <module>  
    from django.db import models  
  File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 40, in <module>  
    backend = load_backend(connection.settings_dict['ENGINE'])  
  File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__  
    return getattr(connections[DEFAULT_DB_ALIAS], item)  
  File "c:\Python27\Lib\site-packages\django\db\utils.py", line 92, in __getitem__  
    backend = load_backend(db['ENGINE'])  
  File "c:\Python27\Lib\site-packages\django\db\utils.py", line 54, in load_backend  
    return import_module('.base', backend_name)  
  File "c:\Python27\Lib\site-packages\django\utils\importlib.py", line 35, in import_module  
    __import__(name)  
  File "c:\Python27\Lib\site-packages\django\db\backends\sqlite3\base.py", line 14, in <module>  
    from django.db import utils  
ImportError: cannot import name utils
Can anyone give me a pointer on how to fix this? I am using Python 2.7.
I had this bug and it was caused by django_nose. I was trying to import django_nose from settings.py to determine if it exists on the system like this:
try:
    import django_nose
    INSTALLED_APPS += ['django_nose']
    TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
except ImportError:
    pass
I modified this to
from imp import find_module
try:
    find_module('django_nose')
    INSTALLED_APPS += ['django_nose']
    TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
except ImportError:
    pass
and my issue was resolved...
I do not know the exact reason, but using Django's python shell i.e {$./manage.py shell} does not throw the error. I think Django does it's own little customization/overriding of python's packages, hence the altercation in the traditional interpreter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With