Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

how to set WSGI of appache2 to work with python 3.7?

I am using ubuntu 16.04 and installed python 3.7 and set it to default using this instructions: Unable to set default python version to python3 in ubuntu when I type python in the console I get python3.7 , i tried to set appache2 to work with python 3.7 using :

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

but still I get exceptions of import packages that are already installed in /var/log/apache2/error.log when try to reach out to the server that I don't get at the terminal like this :

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

and

mod_wsgi (pid=75005): Target WSGI script '/home/ubuntu/my_code/wsgi.py' cannot be loaded as Python module.

even though i have django installed in python 3.7 another error i get is after service restart :

 mod_wsgi (pid=89300): Call to 'site.addsitedir()' failed for '(null)', stopping.

my 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()

What can be the reason for this error?

question from:https://stackoverflow.com/questions/65904521/how-to-set-wsgi-of-appache2-to-work-with-python-3-7

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you need to built python and then built wsgi since the default wsgi is built based on the is system python use this tutorial https://medium.com/@garethbjohnson/serve-python-3-7-with-mod-wsgi-on-ubuntu-16-d9c7ab79e03a


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...