在 Heroku 中部署 Django 后出现错误。查找错误
Having Error after deploying Django in Heroku. LookupError
我刚刚将我的情绪分析 django 应用程序部署到 heroku。部署成功,我可以访问登录注册等功能。但我无法分析文本,因为显然找不到 nltk。但是我已经在我的本地主机上安装并导入了它,并且之前已经可以使用了。
这是我第一次在heroku中部署,所以我对一切都不熟悉。
这是它在我的本地主机中的样子:
这是我尝试分析情绪时 herokuapp live webapp 中的错误。
LookupError at /sentiment/type/
**********************************************************************
Resource e[93mpunkte[0m not found.
Please use the NLTK Downloader to obtain the resource:
e[31m>>> import nltk
>>> nltk.download('punkt')
e[0m
For more information see: https://www.nltk.org/data.html
Attempted to load e[93mtokenizers/punkt/PY3/english.picklee[0m
Searched in:
- '/app/nltk_data'
- '/app/.heroku/python/nltk_data'
- '/app/.heroku/python/share/nltk_data'
- '/app/.heroku/python/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
Request Method: POST
Request URL: https://sentymeter.herokuapp.com/sentiment/type/
Django Version: 4.0
Exception Type: LookupError
Exception Value:
**********************************************************************
Resource e[93mpunkte[0m not found.
Please use the NLTK Downloader to obtain the resource:
e[31m>>> import nltk
>>> nltk.download('punkt')
e[0m
For more information see: https://www.nltk.org/data.html
Attempted to load e[93mtokenizers/punkt/PY3/english.picklee[0m
Searched in:
- '/app/nltk_data'
- '/app/.heroku/python/nltk_data'
- '/app/.heroku/python/share/nltk_data'
- '/app/.heroku/python/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
Exception Location: /app/.heroku/python/lib/python3.8/site-packages/nltk/data.py, line 583, in find
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.8.9
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python38.zip',
'/app/.heroku/python/lib/python3.8',
'/app/.heroku/python/lib/python3.8/lib-dynload',
'/app/.heroku/python/lib/python3.8/site-packages']
Server time: Wed, 05 Jan 2022 20:16:57 +0000
setting.py
"""
Django settings for sentiment_emotion_analysis project.
Generated by 'django-admin startproject' using Django 2.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sentiment.settings")
# import django
# django.setup()
# from django.core.management import call_command
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.DEBUG: 'alert-debug',
messages.INFO: 'alert-info',
messages.SUCCESS: 'success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'danger',
}
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g&x!0fjh8c8)e_-z@gs1^lbngvqwk2(o3s(5zg!o&woxdsu_un'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['sentymeter.herokuapp.com' , '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sentiment',
'user',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sentiment_emotion_analysis.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'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',
],
},
},
]
WSGI_APPLICATION = 'sentiment_emotion_analysis.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
MODELS = os.path.join(BASE_DIR, 'sentiment/models')
谁能帮我解决这个问题?
您似乎安装了 nltk python 软件包,但没有安装任何数据。
如果你想快速修复,你可以连接到你的 heroku (heroku ps:exec
) 和 运行 django shell python manage.py shell
然后安装相关的 nltk 模块来自 python shell:
import nltk
nltk.download('punkt')
既然您希望能够重新部署它,最好创建一个 management command 来执行此操作,并且 运行 它类似于您 运行 迁移的方式。管理命令应该在{app}/management/commands/
下
这样的命令:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Install NLTK stuff'
def handle(self, *args, **options):
import nltk
nltk.download(..) # replace the dots with the relevant corpora
我刚刚将我的情绪分析 django 应用程序部署到 heroku。部署成功,我可以访问登录注册等功能。但我无法分析文本,因为显然找不到 nltk。但是我已经在我的本地主机上安装并导入了它,并且之前已经可以使用了。
这是我第一次在heroku中部署,所以我对一切都不熟悉。
这是它在我的本地主机中的样子:
这是我尝试分析情绪时 herokuapp live webapp 中的错误。
LookupError at /sentiment/type/
**********************************************************************
Resource e[93mpunkte[0m not found.
Please use the NLTK Downloader to obtain the resource:
e[31m>>> import nltk
>>> nltk.download('punkt')
e[0m
For more information see: https://www.nltk.org/data.html
Attempted to load e[93mtokenizers/punkt/PY3/english.picklee[0m
Searched in:
- '/app/nltk_data'
- '/app/.heroku/python/nltk_data'
- '/app/.heroku/python/share/nltk_data'
- '/app/.heroku/python/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
Request Method: POST
Request URL: https://sentymeter.herokuapp.com/sentiment/type/
Django Version: 4.0
Exception Type: LookupError
Exception Value:
**********************************************************************
Resource e[93mpunkte[0m not found.
Please use the NLTK Downloader to obtain the resource:
e[31m>>> import nltk
>>> nltk.download('punkt')
e[0m
For more information see: https://www.nltk.org/data.html
Attempted to load e[93mtokenizers/punkt/PY3/english.picklee[0m
Searched in:
- '/app/nltk_data'
- '/app/.heroku/python/nltk_data'
- '/app/.heroku/python/share/nltk_data'
- '/app/.heroku/python/lib/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- ''
**********************************************************************
Exception Location: /app/.heroku/python/lib/python3.8/site-packages/nltk/data.py, line 583, in find
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.8.9
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python38.zip',
'/app/.heroku/python/lib/python3.8',
'/app/.heroku/python/lib/python3.8/lib-dynload',
'/app/.heroku/python/lib/python3.8/site-packages']
Server time: Wed, 05 Jan 2022 20:16:57 +0000
setting.py
"""
Django settings for sentiment_emotion_analysis project.
Generated by 'django-admin startproject' using Django 2.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sentiment.settings")
# import django
# django.setup()
# from django.core.management import call_command
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.DEBUG: 'alert-debug',
messages.INFO: 'alert-info',
messages.SUCCESS: 'success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'danger',
}
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g&x!0fjh8c8)e_-z@gs1^lbngvqwk2(o3s(5zg!o&woxdsu_un'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['sentymeter.herokuapp.com' , '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sentiment',
'user',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sentiment_emotion_analysis.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'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',
],
},
},
]
WSGI_APPLICATION = 'sentiment_emotion_analysis.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
MODELS = os.path.join(BASE_DIR, 'sentiment/models')
谁能帮我解决这个问题?
您似乎安装了 nltk python 软件包,但没有安装任何数据。
如果你想快速修复,你可以连接到你的 heroku (heroku ps:exec
) 和 运行 django shell python manage.py shell
然后安装相关的 nltk 模块来自 python shell:
import nltk
nltk.download('punkt')
既然您希望能够重新部署它,最好创建一个 management command 来执行此操作,并且 运行 它类似于您 运行 迁移的方式。管理命令应该在{app}/management/commands/
这样的命令:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Install NLTK stuff'
def handle(self, *args, **options):
import nltk
nltk.download(..) # replace the dots with the relevant corpora