python - 如何设置 appache2 的 WSGI 以使用 python 3.7?
问题描述
我正在使用 ubuntu 16.04 并安装了 python 3.7 并使用以下说明将其设置为默认值:
Unable to set default python version to python3 in ubuntu
when I type python
in the console 我得到 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
推荐阅读
- c++ - 将输入流转换为双向量
- elasticsearch - Kibana {"statusCode":403,"error":"Forbidden","message":"Forbidden"}
- javascript - 为什么递归函数中特别需要“null”?
- javascript - jQuery按钮切换文本在onlick上不起作用
- python - 如何在 Python 中将嵌套字典的值与不同数量的键相乘?
- .net - ML.NET:如何解决“具有角色 MatrixColumnIndex 的列应该是已知的基数 U4 键,而是 'UInt32'”
- java - FileInputStream 读取方法不断返回 194
- django - celery 找不到活动任务(本地和 Heroku)
- javascript - React Native Expo 应用程序中的 RefreshView 超时
- ios - 制作动画以滑动和隐藏/显示 UIView(swift 5)