Django/mod_wsgi/Apache - mod_wsgi 未使用为其编译的 Python 版本 - “ModuleNotFoundError:没有名为 'math' 的模块”

2024-01-09

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

我从源代码安装了 mod_wsgi,并且配置它 https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html#configuring-the-source-code针对系统 python3 进行编译,特别是 python3.7.8

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

我的 VirtualHost 配置文件如下所示:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName kumberas.com
        ServerAdmin [email protected] /cdn-cgi/l/email-protection

        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'

我做了一些挖掘并发现了这个wsgi.py https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-installation-in-usemod_wsgi 文档中的文件用于检查 mod_wsgi 正在使用的 python 版本,并在访问该站点时获得以下输出:

sys.version = '3.7.2 (default, Jan 23 2020, 09:44:10) \n[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) 能够使用以下命令运行 Django 应用程序manage.py runserver和 b) 可以运行get_wsgi_application()在 Django shell 中手动。

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


如果使用 virtualenv 或 virtualenvwrapper 创建环境,则需要调用 wsgi.py 中的激活脚本:

python_home = '/home/dan/app/kumberas/venv'

activate_this = python_home + '/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django/mod_wsgi/Apache - mod_wsgi 未使用为其编译的 Python 版本 - “ModuleNotFoundError:没有名为 'math' 的模块” 的相关文章

  • Python 中的流式传输管道

    我正在尝试使用 Python 将 vmstat 的输出转换为 CSV 文件 因此我使用类似的方法转换为 CSV 并将日期和时间添加为列 vmstat 5 python myscript py gt gt vmstat log 我遇到的问题是
  • 搜索多个字段

    我想我没有正确理解 django haystack 我有一个包含多个字段的数据模型 我希望搜索其中两个字段 class UserProfile models Model user models ForeignKey User unique
  • 如何在 Python 中加密并在 Java 中解密?

    我正在尝试在 Python 程序中加密一些数据并将其保存 然后在 Java 程序中解密该数据 在Python中 我像这样加密它 from Crypto Cipher import AES KEY 1234567890123456789012
  • 没有名为 StringIO 的模块

    我有Python 3 6 我想从另一个名为 run py 的 python 文件执行名为 operation py 的 python 文件 In operation py I do from cStringIO import StringI
  • 在 Django OAuth Toolkit 中安全创建新应用程序

    如何将 IsAdminUser 权限添加到 Django OAuth Toolkit 中的 o applications 视图 REST FRAMEWORK DEFAULT PERMISSION CLASSES rest framework
  • Emacs 24.x 上的 IPython 支持

    我对 IPython 与 Emacs 的集成感到困惑 从 Emacs 24 开始 Emacs 附带了自己的python el 该文件是否支持 IPython 还是仅支持 Python 另外 维基百科 http emacswiki org e
  • 在 matplotlib 中的极坐标图上移动径向刻度标签

    From matplotlib 示例 http matplotlib org examples pylab examples polar demo html import numpy as np import seaborn as sbs
  • 如果在等待“read -s”时中断,在子进程中运行 bash 会破坏 tty 的标准输出吗?

    正如 Bakuriu 在评论中指出的那样 这基本上与BASH 输入期间按 Ctrl C 会中断当前终端 https stackoverflow com questions 31808863 bash ctrlc during input b
  • Python新式类和__subclasses__函数

    有人可以向我解释为什么这有效 在 Python 2 5 中 class Foo object pass class Bar Foo pass print Foo subclasses 但这不是 class Foo pass class Ba
  • 使用 python 绘制正值小提琴图

    我发现小提琴图信息丰富且有用 我使用 python 库 seaborn 然而 当应用于正值时 它们几乎总是在低端显示负值 我发现这确实具有误导性 尤其是在处理现实数据集时 在seaborn的官方文档中https seaborn pydata
  • Matplotlib 中 x 轴标签的频率和旋转

    我在下面编写了一个简单的脚本来使用 matplotlib 生成图形 我想将 x tick 频率从每月增加到每周并轮换标签 我不知道从哪里开始 x 轴频率 我的旋转线产生错误 TypeError set xticks got an unexp
  • python中的[][](双方括号运算符)运算符是什么?

    我是 python 新手 我一直在寻找分配变量时进行三元运算的正确方法 我发现有人在堆栈溢出上发表了一个帖子 提出了这样的建议 var smaller bigger 7 gt 1 其中左边的值为 False 右边的值为 True 我运行它并
  • 在 keras 中保存和加载权重

    我试图从我训练过的模型中保存和加载权重 我用来保存模型的代码是 TensorBoard log dir output model fit generator image a b gen batch size steps per epoch
  • Mac OSX 10.6 上的 Python mysqldb 不工作

    我正在使用 Python 2 7 并尝试让 Django 项目在 MySQL 后端运行 我已经下载了 mysqldb 并按照此处的指南进行操作 http cd34 com blog programming python mysql pyth
  • Anaconda 无法导入 ssl 但 Python 可以

    Anaconda 3 Jupyter笔记本无法导入ssl 但使用Atom终端导入ssl没有问题 我尝试在 Jupyter 笔记本中导入 ssl 但出现以下错误 C ProgramData Anaconda3 lib ssl py in
  • 混淆矩阵不支持多标签指示符

    multilabel indicator is not supported是我在尝试运行时收到的错误消息 confusion matrix y test predictions y test is a DataFrame其形状为 Horse
  • 如何与其他用户一起使用 pyenv?

    如何与其他用户一起使用 pyenv 例如 如果我在用户 test 的环境中安装了 pyenv 则当我以 test 身份登录时可以使用 pyenv 但是 当我以其他用户 例如 root 身份登录时如何使用 pyenv 即使你这么做了 我也会s
  • Django 与谷歌图表

    我试图让谷歌图表显示在我的页面上 但我不知道如何将值从 django 视图传递到 javascript 以便我可以绘制图表 姜戈代码 array Year Sales Expenses 2004 1000 400 2005 1170 460
  • mod_rewrite, .htaccess 连接mysql数据库

    我希望 htaccess 文件中的 mod rewrite 链接到 mysql 数据库以向我提供映射信息 具体来说 我使用单个代码库来托管多个站点 因此 如果用户请求图像 例如 http www example com images car
  • 查找总和为给定数字的值组合的函数

    这个帖子查找提供的 Sum 值的组合 https stackoverflow com a 20194023 1561176呈现函数subsets with sum 它在数组中查找总和等于给定值的值的组合 但由于这个帖子已经有6年多了 我发这

随机推荐