Python ImportError:没有名为';环境';在django有gunicorn
我正在使用Ubuntu 14.04和Django 2.0.5以及Django Cookiecutter。我正在尝试在DigitalOcean上启动Django服务器,并尝试将gunicorn绑定到0.0.0.0:8000。python manage.py runserver工作正常,但问题是它表示无法导入environ。非常感谢您提供的任何建议,谢谢 我跑了 pip安装-r base.txt pip安装-r local.txt pip install-r production.txt 并重新安装了django Enviro 0.4.4 这是我在运行以下gunicorn命令时收到的错误: sudo gunicorn--bind 0.0.0.0:8000 config.wsgi:application 生产.进口Python ImportError:没有名为';环境';在django有gunicorn,python,django,environ,Python,Django,Environ,我正在使用Ubuntu 14.04和Django 2.0.5以及Django Cookiecutter。我正在尝试在DigitalOcean上启动Django服务器,并尝试将gunicorn绑定到0.0.0.0:8000。python manage.py runserver工作正常,但问题是它表示无法导入environ。非常感谢您提供的任何建议,谢谢 我跑了 pip安装-r base.txt pip安装-r local.txt pip install-r production.txt 并重新安装
import logging
from .base import * # noqa
from .base import env
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
# This allows easy placement of apps within the interior
# manaland directory.
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_path, "manaland"))
execute_from_command_line(sys.argv)
您需要使用本地设置运行manage.py文件
python manage.py runserver --settings=config.settings.production
您需要为数据库设置环境变量: 如果您在linux计算机上:
$ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb>
$export DATABASE\u URL=postgres://postgres:@127.0.0.1:5432/
cookiecutter doc可以为您提供更多帮助:
链接:Uhm。。。我怀疑问题在于生产中的进口.py。您能在
production.py
中复制并粘贴导入吗?嗨,Karim,我添加了来自production.py的导入。您是否尝试使用不同的设置运行manage.py shell?(qa,prod…)您是否尝试删除gunicorn命令中的sudo
?是的,我正在使用sudo gunicorn-b 0.0.0.0:8000 config.wsgi:application,我刚刚添加了manage.py
python manage.py runserver --settings=config.settings.production
$ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb>