gpt4 book ai didi

python - Django - Foreman 找不到已安装的模型

转载 作者:行者123 更新时间:2023-12-02 08:47:19 26 4
gpt4 key购买 nike

我正在尝试使用Foreman/Honcho管理我的基于 Procfile 的 Django 应用程序。当我启动应用程序查看正常的 python manage.py runserver 时,一切正常。但是,当我通过 honcho startforeman start web 启动应用程序时,我收到此错误:

11:59:31 system | web.1 started (pid=27959)
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Starting gunicorn 19.4.5
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Listening at: http://0.0.0.0:5000 (27959)
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Using worker: sync
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27962] [INFO] Booting worker with pid: 27962
11:59:31 web.1 | [2016-04-26 18:59:31 +0000] [27962] [ERROR] Exception in worker process:
11:59:31 web.1 | Traceback (most recent call last):
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
11:59:31 web.1 | worker.init_process()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
11:59:31 web.1 | self.load_wsgi()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
11:59:31 web.1 | self.wsgi = self.app.wsgi()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
11:59:31 web.1 | self.callable = self.load()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
11:59:31 web.1 | return self.load_wsgiapp()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
11:59:31 web.1 | return util.import_app(self.app_uri)
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/util.py", line 357, in import_app
11:59:31 web.1 | __import__(module)
11:59:31 web.1 | File "../wsgi.py", line 17, in <module>
11:59:31 web.1 | application = get_wsgi_application()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
11:59:31 web.1 | django.setup()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
11:59:31 web.1 | apps.populate(settings.INSTALLED_APPS)
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 85, in populate
11:59:31 web.1 | app_config = AppConfig.create(entry)
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/django/apps/config.py", line 90, in create
11:59:31 web.1 | module = import_module(entry)
11:59:31 web.1 | File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
11:59:31 web.1 | __import__(name)
11:59:31 web.1 | ImportError: No module named django_messages
11:59:31 web.1 | [2016-04-26 18:59:31 +0000] [27962] [INFO] Worker exiting (pid: 27962)
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Shutting down: Master
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Reason: Worker failed to boot.
11:59:31 system | web.1 stopped (rc=3)

这是尝试安装 django-message模块。我对其他模块也有同样的问题。我也遇到了同样的问题 django-webpack-loader 。我还应该提到的是,我在 virtualenv 内和停用时都收到错误。

这是安装 django-messages 的命令:

$> pip install django-messages
Requirement already satisfied (use --upgrade to upgrade): django-messages in ./lib/python2.7/site-packages

已安装的应用程序;

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_app',
'django_messages',
)

我不确定我可以提供哪些其他信息来帮助排除故障,但基本问题是如何让已安装的应用程序与工头/老板一起使用?

最佳答案

Honcho 和 Foreman 不使用 virtualenv 中的 Python 可执行文件和库,虽然您没有包含 Honcho Procfile,但仅调用 python 将使用系统范围的可执行文件和库。

不幸的是,您不能只调用 /path/to/virtualenv/bin/activate 作为 Procfile 的一部分,因为当子进程之一退出时,Honcho 也会退出,如所述 in this Github issue thread 。不过,您可以在一个子 shell 中执行此脚本和 Python 脚本,使用 && 运算符将它们链接在一起:

web: source venv/bin/activate && python manage.py 

或者,您可能会更好地修改 wsgi.py 包装器,以便在导入 Django 应用程序之前显式引入 virtualenv 的库:

# Activate your virtual env
activate_env=os.path.expanduser("/path/to/virtualenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

这些应该在导入任何模块(os 除外)之前执行,以确保您的应用程序读取正确的站点库。

最后,Honcho 本身支持将 .env 文件与 Procfile 一起使用,Procfile 设置进程运行的环境。该文件的格式与任何 bash 脚本相同。您可以使用 .env 文件设置 PYTHONPATHPYTHONHOME 以指向 Virtualenv 中的库,然后从 Procfile 中指定 Virtualenv 内的显式 Python 解释器。

.env 文件

PYTHONHOME=/path/to/virtualenv/lib/python2.7
PYTHONHOME=

关于python - Django - Foreman 找不到已安装的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36873730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com