我使用的是 ubuntu 16.04 并安装了 python 3.7 并使用以下说明将其设置为默认值:无法在 ubuntu 中将默认 python 版本设置为 python3 https://stackoverflow.com/questions/41986507/unable-to-set-default-python-version-to-python3-in-ubuntu当我打字时python
在控制台中我得到 python3.7 ,我尝试使用以下命令将 apache2 设置为与 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
and
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()
导致此错误的原因可能是什么?