Django 1.5 + TastyPie 0.10 Gives"无法导入名称ModelResource"

时间:2013-09-13 21:33:42

标签: python django apache tastypie

更新Django& Tastypie我收到一个“无法导入名称ModelResource”。我该如何解决这个问题?

我目前正在尝试将Django安装更新为Django 1.5,以及最新版本的Tastypie。我之前已经完成了两次(一次在我的开发MacBook Pro上,再次在预发布服务器上,与我现在正在升级的服务器相同)。两次我都记得有麻烦,但两次我都让它工作......我不知道怎么做!

现在已经发生了第三次,我的疯狂“卸载然后重新安装直到它工作”策略到目前为止失败了。我正在运行Apache服务器,但我的预生产工作正常(我已经检查过所有django和模块版本都匹配)。

有没有人遇到过这个问题并且没有解决这个问题的神奇序列?

完整引用跟踪:

Environment:


Request Method: GET
Request URL: http://10.32.232.50/

Django Version: 1.5.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django_extensions',
 'floppyforms',
 'crispy_forms',
 'tastypie',
 'userProfile',
 'modeling',
 'aliance',
 'launchpad',
 'visitorlog',
 'experience_controller')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\core\handlers\base.py" in get_response
  103.                     resolver_match = resolver.resolve(request.path_info)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\core\urlresolvers.py" in resolve
  319.             for pattern in self.url_patterns:
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\core\urlresolvers.py" in url_patterns
  347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\core\urlresolvers.py" in urlconf_module
  342.             self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "c:\AbacusCore\abacus\urls.py" in <module>
  3. from api import *
File "c:\AbacusCore\abacus\api.py" in <module>
  4. from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
File "C:\Python27\lib\site-packages\django_tastypie-0.10.0-py2.7.egg\tastypie\resources.py" in <module>
  19. from tastypie.authentication import Authentication
File "C:\Python27\lib\site-packages\django_tastypie-0.10.0-py2.7.egg\tastypie\authentication.py" in <module>
  14. from tastypie.compat import User, username_field
File "C:\Python27\lib\site-packages\django_tastypie-0.10.0-py2.7.egg\tastypie\compat.py" in <module>
  14.         User = get_user_model()
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\contrib\auth\__init__.py" in get_user_model
  127.     user_model = get_model(app_label, model_name)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\db\models\loading.py" in get_model
  230.             self._populate()
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\db\models\loading.py" in _populate
  75.                     self.load_app(app_name)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\db\models\loading.py" in load_app
  96.             models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django-1.5.2-py2.7.egg\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "c:\AbacusCore\visitorlog\models.py" in <module>
  6. from tastypie.resources import ModelResource

Exception Type: ImportError at /
Exception Value: cannot import name ModelResource

1 个答案:

答案 0 :(得分:0)

你的PYTHONPATH安装了tastypie吗?


如果你打开一个命令提示符(如果你使用它,请确保你在正确的虚拟环境中)并运行:

bash: echo $PYTHONPATH

或者,从异常点打开的python调试器:

>>>import os
>>>os.environ['PYTHONPATH'].split(os.pathsep)

然后确保您安装tastypie的目录位于列出的目录之一。