ImportError:没有名为tastypie.api的模块

时间:2016-11-15 10:22:31

标签: python django tastypie

当我运行Django(1.9)时,我收到以下错误消息" ImportError:没有名为tastypie.api的模块"。搜索上一篇文章没有人有用(例如here)。

我想这是因为我使用了最新的django-tastypie(django-tastypie-0.13.3)。以下是我所拥有的v-env的当前配置。

请告诉我你的建议。

提前致意并表示感谢。

Django(1.9) 枕头(3.4.2) 点子(9.0.1) setuptools(28.8.0) 轮(0.30.0a0)

(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7fb98582dcf8>
Traceback (most recent call last):
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check(display_num_errors=True)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 10, in check_url_config
    return check_resolver(resolver)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 19, in check_resolver
    for pattern in resolver.url_patterns:
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/var/www/CordeliaHanelBackend-master/CordeliaHanelBackend/urls.py", line 8, in <module>
    from tastypie.api import Api
ImportError: No module named tastypie.api

如果添加到INSTALLED_APP,我会得到以下堆栈跟踪。

INSTALLED_APPS = [

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 'CordeliaHanelBackend',
    'tastypie',
    'StudioHanel',
]



(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
    commands = get_commands()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
    result = user_function(*args, **kwds)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
    for app_config in reversed(list(apps.get_app_configs())):
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
    self.check_apps_ready()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# 

以下是pip冻结:

(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# pip freeze
Django==1.9
Pillow==3.4.2

编辑:如果您想知道URLs.py的设置。

Django main urls.py

# from django.conf.urls import patterns, include, url
from django.conf.urls import *
from django.conf import settings
from django.conf.urls.static import static

from django.contrib import admin

from tastypie.api import Api
from StudioHanel.api import *

admin.autodiscover()

studioHanel_api = Api(api_name='studiohanel')
studioHanel_api.register(MenuResource())
studioHanel_api.register(AboutResource())
studioHanel_api.register(InteriorResource())
studioHanel_api.register(InteriorImageResource())
studioHanel_api.register(CaseStudyResource())
studioHanel_api.register(CaseStudyBulletResource())
studioHanel_api.register(ProductDesignResource())
studioHanel_api.register(ProductDesignImageResource())
studioHanel_api.register(ContactResource())

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'CordeliaHanelBackend.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^api/', include(studioHanel_api.urls)),
    url(r'^', include('StudioHanel.urls', namespace='StudioHanel')),
)

Django Application urls.py

from django.conf.urls import patterns, include, url

from StudioHanel import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^contact/', views.contact, name='contact'),
)

更新

重新安装没有sudo的tastypie:#pip install django-tastypie

并跳转到下一个错误,如下所示:

(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# python manage.py runserver
Performing system checks...

/var/www/CordeliaHanelBackend-master/StudioHanel/urls.py:7: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^contact/', views.contact, name='contact'),

/var/www/CordeliaHanelBackend-master/CordeliaHanelBackend/urls.py:31: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^', include('StudioHanel.urls', namespace='StudioHanel')),

System check identified some issues:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS.

System check identified 1 issue (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7fea16b35c08>
Traceback (most recent call last):
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    self.check_migrations()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 163, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 170, in build_graph
    self.load_disk()
  File "/var/www/CordeliaHanelBackend-master/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 105, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/var/www/CordeliaHanelBackend-master/StudioHanel/migrations/0002_auto__add_field_interior_theme.py", line 2, in <module>
    from south.utils import datetime_utils as datetime
ImportError: No module named south.utils

所以我安装了南方:

# pip install South
Collecting South
Installing collected packages: South
Successfully installed South-1.0.2

现在,如下所示,我想我需要谷歌。

(env) root@mike-VirtualBox:/var/www/CordeliaHanelBackend-master# python manage.py runserver
Performing system checks...

/var/www/CordeliaHanelBackend-master/StudioHanel/urls.py:7: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^contact/', views.contact, name='contact'),

/var/www/CordeliaHanelBackend-master/CordeliaHanelBackend/urls.py:31: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^', include('StudioHanel.urls', namespace='StudioHanel')),

System check identified some issues:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS.

System check identified 1 issue (0 silenced).
There is no South database module 'south.db.sqlite3' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.

1 个答案:

答案 0 :(得分:2)

在您的案例中有几点需要注意。首先,您正在使用virtualenv。因此,应该在没有sudo

的情况下安装库
pip install django-tastypie

应该在INSTALLED_APPS

中考虑订单
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tastypie',
    'CordeliaHanelBackend',
    'StudioHanel',
]