Django/mod_wsgi/apache-mod_wsgi没有使用为其编译的Python版本-"ModuleNotFoundError:没有命名的模块。 [英] Django/mod_wsgi/Apache - mod_wsgi is not using the Python version it was compiled for - "ModuleNotFoundError: No module named 'math' "

查看:15
本文介绍了Django/mod_wsgi/apache-mod_wsgi没有使用为其编译的Python版本-"ModuleNotFoundError:没有命名的模块。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Ubuntu 16.04.6服务器上部署一个带有Apache2和mod_wsgi的Django应用程序,但我很难让mod_wsgi使用正确的python版本。

我从源安装了mod_wsgi,configured it是针对系统python3编译的,特别是python3.7.8

我的Django应用程序的虚拟环境也在运行python3.7.8。

我的Virtual主机配置文件如下所示:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName kumberas.com
        ServerAdmin webmaster@localhost.com

        WSGIScriptAlias / /home/dan/app/kumberas/kumberas/main/wsgi.py
        Alias /static/ /home/dan/app/kumberas/kumberas/static/

        <Directory /home/dan/app/kumberas/kumberas/static>
            Require all granted
        </Directory>

        <Directory /home/dan/app/kumberas/venv>
            Require all granted
        </Directory>

        <Directory /home/dan/app/kumberas/kumberas/main>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>

        <Location />
            AuthType Basic
            AuthName "Restricted Content"
            AuthUserFile /etc/apache2/.htpasswd
            Require user kr
            AuthBasicProvider file
        </Location>

        WSGIDaemonProcess kumberas 
            python-home=/home/dan/app/kumberas/venv 
            python-path=/home/dan/app/kumberas
        WSGIProcessGroup kumberas

    </VirtualHost>
</IfModule>

当我尝试访问该站点时,在我的apache错误日志中收到500错误和以下内容。

[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603] mod_wsgi (pid=21635): Failed to exec Python script file '/home/dan/app/kumberas/kumberas/main/wsgi.py'.
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603] mod_wsgi (pid=21635): Exception occurred processing WSGI script '/home/dan/app/kumberas/kumberas/main/wsgi.py'.
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603] Traceback (most recent call last):
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]   File "/home/dan/app/kumberas/kumberas/main/wsgi.py", line 12, in <module>
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]     from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]   File "/home/dan/app/kumberas/venv/lib/python3.7/site-packages/django/__init__.py", line 1, in <module>
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]     from django.utils.version import get_version
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]   File "/home/dan/app/kumberas/venv/lib/python3.7/site-packages/django/utils/version.py", line 1, in <module>
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]     import datetime
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]   File "/usr/lib/python3.7/datetime.py", line 8, in <module>
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603]     import math as _math
[wsgi:error] [pid 21635] [remote xx.xx.xx.xx:58603] ModuleNotFoundError: No module named 'math'

我做了一些挖掘,在mod_wsgi文档中找到了这个wsgi.py文件,用于检查mod_wsgi正在使用的python版本,当我访问该站点时,得到以下输出:

sys.version = '3.7.2 (default, Jan 23 2020, 09:44:10) 
[GCC 5.4.0 20160609]'
sys.prefix = '/home/dan/app/kumberas/venv'

我假设这里的问题是不匹配的python版本3.7.8 != 3.7.2,但据我所知,服务器上没有安装python3.7.2,我已经重新安装了mod_wsgi多次,以确保我将其配置为使用3.7.8。

我还确认,在虚拟环境中,a)能够使用manage.py runserver运行Django应用程序,b)可以在Django外壳中手动运行get_wsgi_application()

有谁知道此版本不匹配是否是问题所在,以及如何解决该问题?

推荐答案

您的版本可能不匹配。某些Linux仍使用python2.7作为默认设置。

还可以使用locate python和/或locate python3检查系统是否有多个版本的Python

如果这是modwsgi上的问题,您可能更容易从链接https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html后面的源代码构建mod_wsgi

这篇关于Django/mod_wsgi/apache-mod_wsgi没有使用为其编译的Python版本-&quot;ModuleNotFoundError:没有命名的模块。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆