1

更新 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
4

1 回答 1

0

你在 PYTHONPATH 中安装了 sweetpie 吗?


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

bash: echo $PYTHONPATH

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

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

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

于 2013-09-13T22:24:27.180 回答