RuntimeError:populate()在Django中不可重入

时间:2015-07-24 12:55:57

标签: django apache python-2.7 ubuntu-14.04

我正在尝试部署django网站。项目名称是pom。 我正在尝试使用apache2在ec2服务器上运行django网站并收到以下错误:

Apache错误文件:

[Fri Jul 24 12:37:33.621285 2015] [:info] [pid 20446:tid 140024755709824] mod_wsgi (pid=20446): Attach interpreter ''.
[Fri Jul 24 12:37:33.621462 2015] [:info] [pid 20446:tid 140024755709824] mod_wsgi (pid=20446): Adding '/home/ubuntu/.virtualenvs/edusamosa/lib/python2.7/site-packages/' to path.
[Fri Jul 24 12:37:44.145762 2015] [authz_core:debug] [pid 20448:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11934] AH01626: authorization result of Require all granted: granted
[Fri Jul 24 12:37:44.145888 2015] [authz_core:debug] [pid 20448:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11934] AH01626: authorization result of <RequireAny>: granted
[Fri Jul 24 12:37:44.145947 2015] [authz_core:debug] [pid 20448:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11934] AH01626: authorization result of Require all granted: granted
[Fri Jul 24 12:37:44.145953 2015] [authz_core:debug] [pid 20448:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11934] AH01626: authorization result of <RequireAny>: granted
[Fri Jul 24 12:37:44.152795 2015] [:info] [pid 20446:tid 140024564070144] mod_wsgi (pid=20446): Create interpreter 'www.edusamosa.in|'.
[Fri Jul 24 12:37:44.153592 2015] [:info] [pid 20446:tid 140024564070144] mod_wsgi (pid=20446): Adding '/home/ubuntu/.virtualenvs/edusamosa/lib/python2.7/site-packages/' to path.
[Fri Jul 24 12:37:44.152795 2015] [:info] [pid 20446:tid 140024564070144] mod_wsgi (pid=20446): Create interpreter 'www.edusamosa.in|'.
[Fri Jul 24 12:37:44.153592 2015] [:info] [pid 20446:tid 140024564070144] mod_wsgi (pid=20446): Adding '/home/ubuntu/.virtualenvs/edusamosa/lib/python2.7/site-packages/' to path.
[Fri Jul 24 12:37:44.153884 2015] [:info] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213] mod_wsgi (pid=20446, process='pom', application='www.edusamosa.in|'): Loading WSGI script '/home/ubuntu/pom/pom/wsgi.py'.
[Fri Jul 24 12:37:44.354165 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213] mod_wsgi (pid=20446): Target WSGI script '/home/ubuntu/pom/pom/wsgi.py' cannot be loaded as Python module.
[Fri Jul 24 12:37:44.354189 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213] mod_wsgi (pid=20446): Exception occurred processing WSGI script '/home/ubuntu/pom/pom/wsgi.py'.
[Fri Jul 24 12:37:44.354222 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213] Traceback (most recent call last):
[Fri Jul 24 12:37:44.354238 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/home/ubuntu/pom/pom/wsgi.py", line 19, in <module>
[Fri Jul 24 12:37:44.354362 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     application = get_wsgi_application()
@                   [Fri Jul 24 12:37:44.354238 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/home/ubuntu/pom/pom/wsgi.py", line 19, in <module>
[Fri Jul 24 12:37:44.354362 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     application = get_wsgi_application()
[Fri Jul 24 12:37:44.354377 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Fri Jul 24 12:37:44.354416 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     django.setup()
[Fri Jul 24 12:37:44.354428 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
[Fri Jul 24 12:37:44.354465 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     apps.populate(settings.INSTALLED_APPS)
[Fri Jul 24 12:37:44.354476 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
[Fri Jul 24 12:37:44.354590 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     app_config = AppConfig.create(entry)
[Fri Jul 24 12:37:44.354602 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create
[Fri Jul 24 12:37:44.354590 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     app_config = AppConfig.create(entry)
[Fri Jul 24 12:37:44.354602 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create
[Fri Jul 24 12:37:44.354697 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     module = import_module(entry)
[Fri Jul 24 12:37:44.354708 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Fri Jul 24 12:37:44.354765 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213]     __import__(name)
[Fri Jul 24 12:37:44.354793 2015] [:error] [pid 20446:tid 140024564070144] [remote 49.248.57.164:51213] ImportError: No module named allauth
[Fri Jul 24 12:37:45.251341 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of Require all granted: granted, referer: http://edusamosa.in/
[Fri Jul 24 12:37:45.251496 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of <RequireAny>: granted, referer: http://edusamosa.in/
[Fri Jul 24 12:37:45.251559 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of Require all granted: granted, referer: http://edusamosa.in/
         [Fri Jul 24 12:37:45.251496 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of <RequireAny>: granted, referer: http://edusamosa.in/
[Fri Jul 24 12:37:45.251559 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of Require all granted: granted, referer: http://edusamosa.in/
[Fri Jul 24 12:37:45.251565 2015] [authz_core:debug] [pid 20447:tid 140024656201472] mod_authz_core.c(802): [client 49.248.57.164:11938] AH01626: authorization result of <RequireAny>: granted, referer: http://edusamosa.in/
[Fri Jul 24 18:07:45.251722 2015] [:info] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] mod_wsgi (pid=20446, process='pom', application='www.edusamosa.in|'): Loading WSGI script '/home/ubuntu/pom/pom/wsgi.py'.
[Fri Jul 24 18:07:45.252817 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] mod_wsgi (pid=20446): Target WSGI script '/home/ubuntu/pom/pom/wsgi.py' cannot be loaded as Python module.
[Fri Jul 24 18:07:45.252831 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] mod_wsgi (pid=20446): Exception occurred processing WSGI script '/home/ubuntu/pom/pom/wsgi.py'.
[Fri Jul 24 18:07:45.252850 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] Traceback (most recent call last):
[Fri Jul 24 18:07:45.252870 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/home/ubuntu/pom/pom/wsgi.py", line 19, in <module>
                [Fri Jul 24 18:07:45.252850 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] Traceback (most recent call last):
[Fri Jul 24 18:07:45.252870 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/home/ubuntu/pom/pom/wsgi.py", line 19, in <module>
[Fri Jul 24 18:07:45.252913 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]     application = get_wsgi_application()
[Fri Jul 24 18:07:45.252923 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Fri Jul 24 18:07:45.252940 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]     django.setup()
[Fri Jul 24 18:07:45.252948 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
[Fri Jul 24 18:07:45.252961 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]     apps.populate(settings.INSTALLED_APPS)
[Fri Jul 24 18:07:45.252969 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 78, in populate
[Fri Jul 24 18:07:45.252981 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]     raise RuntimeError("populate() isn't reentrant")
@                              
                                   @        [Fri Jul 24 18:07:45.252969 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 78, in populate
[Fri Jul 24 18:07:45.252981 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879]     raise RuntimeError("populate() isn't reentrant")
[Fri Jul 24 18:07:45.252996 2015] [:error] [pid 20446:tid 140024648070912] [remote 49.248.57.164:58879] RuntimeError: populate() isn't reentrant
~                                           

我的pom.settings.py如下:

"""
Django settings for pom project.

Generated by 'django-admin startproject' using Django 1.8.2.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/



ALLOWED_HOSTS = ['*']


# Application definition
'''
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
    # other finders..
    # 'compressor.finders.CompressorFinder',
)
'''
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'ckeditor',
    'reviewandrating',
    'links',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.linkedin',
    'import_export',
    'haystack',
    'mathfilters',

)
# Ankur's Setting.py
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    "django.core.context_processors.request",
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.tz',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.request',
    'allauth.account.context_processors.account',



)
SITE_ID = 3
AUTH_PROFILE_MODULE = 'links.UserProfile'
LOGIN_URL = '/'

SOCIALACCOUNT_ADAPTER = 'links.my_adapter.MyAdapter'

SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['email'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'METHOD': 'js_sdk',
        'VERIFIED_EMAIL': False
    },

    'google':
        {'SCOPE': ['profile', 'email'],
         'AUTH_PARAMS': {'access_type': 'online'}},
    'linkedin':
        {'SCOPE': ['r_emailaddress'],
         'PROFILE_FIELDS': ['id',
                           'first-name',
                            'last-name',
                            'email-address',
                            'picture-url',
                            'public-profile-url']}

}

LOGIN_REDIRECT_URL = '/'

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'pom.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['/home/ubuntu/pom/templates/'],  # This is where you add the template directory
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'allauth.account.context_processors.account',
                'allauth.socialaccount.context_processors.socialaccount',
            ],
        },
    },
]
WSGI_APPLICATION = 'pom.wsgi.application'
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://localhost:8983/solr/',
        'TIMEOUT': 60 * 5,
        'INCLUDE_SPELLING': True,
        'BATCH_SIZE': 100,
        'EXCLUDED_INDEXES': ['thirdpartyapp.search_indexes.BarIndex'],
    }
}

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'hidden',
        'USER': 'ubuntu',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    '',
    '/home/ubuntu/pom/static/img/',
    '/home/ubuntu/pom/static/css/',
    '/home/ubuntu/pom/static/js/',
)

# TEMPLATE_LOADERS = (
# 'django.template.loaders.filesystem.Loader',
#     'django.template.loaders.app_directories.Loader',
#     #django.template.loaders.eggs.Loader',
# )

TEMPLATE_DIRS = (
    # os.path.join(BASE_DIR, 'templates'),
    '/home/ubuntu/pom/templates/',

)
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'full',
        'height': 300,
        'width': 900,
    },
}

CKEDITOR_UPLOAD_PATH = "uploads/"

CKEDITOR_IMAGE_BACKEND = 'Pillow'

CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

STATIC_ROOT = '/home/ubuntu/pom/static/'

MEDIA_ROOT = '/home/ubuntu/pom/media/'

MEDIA_URL = '/media/'

HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

wsgi.py文件如下:

"""
WSGI config for pom project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
import sys
from os.path import abspath, dirname, join
#sys.path.insert(0, '/home/ubuntu/deploy/pom')
sys.path.insert(0, abspath(join(dirname(__file__), "../")))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pom.settings")

application = get_wsgi_application()

1 个答案:

答案 0 :(得分:5)

错误消息清楚地表明:

ImportError: No module named allauth

populate()不可重入错误是当mod_wsgi在第一次错误之后尝试重新加载WSGI脚本文件时发生的错误,并且发现Django由于第一个错误而被初始化了一半而因此放弃了。

修复了未找到allauth模块的问题,后一个错误应该消失。