如何解决Phusion 乘客应用服务器无法启动 Web 应用程序,ModuleNotFoundError - Django [已解决]
当我使用 pip install -e git+https://github.com/breduin/das.git#egg=django_ajax_selects
从 github 安装第三个站点应用程序时,我的站点无法启动并出现以下错误:
Web application Could not be started by the Phusion Passenger application server.
/usr/share/passenger/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import sys,os,re,imp,threading,signal,traceback,socket,select,struct,logging,errno
Traceback (most recent call last):
File "/usr/share/passenger/helper-scripts/wsgi-loader.py",line 369,in <module>
app_module = load_app()
File "/usr/share/passenger/helper-scripts/wsgi-loader.py",line 76,in load_app
return imp.load_source('passenger_wsgi',startup_file)
File "/opt/python/python-3.8.6/lib/python3.8/imp.py",line 171,in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>",line 702,in _load
File "<frozen importlib._bootstrap>",line 671,in _load_unlocked
File "<frozen importlib._bootstrap_external>",line 783,in exec_module
File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_removed
File "/var/www/u1234567/data/www/mysite/passenger_wsgi.py",line 7,in <module>
application = get_wsgi_application()
File "/var/www/u1234567/data/env/lib/python3.8/site-packages/django/core/wsgi.py",line 12,in get_wsgi_application
django.setup(set_prefix=False)
File "/var/www/u1234567/data/env/lib/python3.8/site-packages/django/__init__.py",line 24,in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/u1234567/data/env/lib/python3.8/site-packages/django/apps/registry.py",line 91,in populate
app_config = AppConfig.create(entry)
File "/var/www/u1234567/data/env/lib/python3.8/site-packages/django/apps/config.py",line 90,in create
module = import_module(entry)
File "/opt/python/python-3.8.6/lib/python3.8/importlib/__init__.py",line 127,in import_module
return _bootstrap._gcd_import(name[level:],package,level)
File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
File "<frozen importlib._bootstrap>",line 991,in _find_and_load
File "<frozen importlib._bootstrap>",line 973,in _find_and_load_unlocked
ModuleNotFoundError: No module named 'ajax_select'
在目录env/lib/python3.8/site-packages/
中,通常放置PyPI的所有包的地方可以找到egg文件,
django-ajax-selects.egg-link
/var/www/u1234567/data/env/src/django-ajax-selects
.
路径正确,应用django-ajax-selects就放在那里。
如果没有来自 github 的这个应用程序和来自 PyPI 的其他应用程序,我的网站就可以正常启动。 服务器似乎无法识别蛋链接或路径,但我不知道如何更正。
解决方法
SO-effect,在写问题时我自己找到了答案:需要在 passenger_wsgi.py 中添加包的路径(在 egg-link 文件中):
# -*- coding: utf-8 -*-
import os,sys
sys.path.insert(0,'/var/www/u1234567/data/www/mysite/mysite')
sys.path.insert(1,'/var/www/u1234567/data/env/lib/python3.8/site-packages')
sys.path.insert(2,'/var/www/u1234567/data/env/src/django-ajax-selects') #<---- this path
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。