gpt4 book ai didi

python - 如何设置 appache2 的 WSGI 以使用 python 3.7?

转载 作者:行者123 更新时间:2023-12-03 13:42:28 25 4
gpt4 key购买 nike

我正在使用 ubuntu 16.04 并安装了 python 3.7 并使用以下说明将其设置为默认值:
Unable to set default python version to python3 in ubuntu
当我输入 python在我得到 python3.7 的控制台中,我尝试将 appache2 设置为与 python 3.7 一起使用:

sudo add-apt-repository --yes ppa:deadsnakes/ppa
sudo apt-get update --yes
sudo apt-get install --yes python3.7
sudo apt-get install --yes python3-pip
sudo apt-get --yes install python3-pip apache2 libapache2-mod-wsgi-py3
sudo a2enmod wsgi
sudo apt install --yes python-django-common
sudo apt-get install --yes python-django
但是当我尝试访问我在终端上没有得到的服务器时,我仍然会遇到已经安装在/var/log/apache2/error.log 中的导入包的异常:
Traceback (most recent call last):
File "/home/ubuntu/my_code/wsgi.py", line 11, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
mod_wsgi (pid=75005): Target WSGI script '/home/ubuntu/my_code/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=75005): Exception occurred processing WSGI script '/home/ubuntu/my_code/wsgi.py'.
Traceback (most recent call last):
File "/home/ubuntu/my_code/wsgi.py", line 11, in <module>
from django.core.wsgi import get_wsgi_application
mod_wsgi (pid=75005): Target WSGI script '/home/ubuntu/my_code/wsgi.py' cannot be loaded as Python module.
即使我在 python 3.7 中安装了 django
我得到的另一个错误是服务重启后:
 mod_wsgi (pid=89300): Call to 'site.addsitedir()' failed for '(null)', stopping.
我的 wsgiy.py :
import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "servicesite.settings")
path='/home/ubuntu/my_code/'

if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'my_code.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
这个错误的原因是什么?

最佳答案

您需要构建 python 然后构建 wsgi,因为默认 wsgi 是基于 is system python 构建的,请使用本教程
https://medium.com/@garethbjohnson/serve-python-3-7-with-mod-wsgi-on-ubuntu-16-d9c7ab79e03a

关于python - 如何设置 appache2 的 WSGI 以使用 python 3.7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65904521/

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