【问题标题】:Django on Windows Server using mod_wsgi. No module named 'lxml.etree'Django 在 Windows Server 上使用 mod_wsgi。没有名为“lxml.etree”的模块
【发布时间】:2020-06-09 18:33:22
【问题描述】:

我正在通过 Apache 将一个新的 Django 项目部署到本地 Windows 服务器,其中包含两个预先存在的 Django 项目。该站点在服务器上本地运行时可以工作,但不能通过 WSGI 运行。我正在使用 mailmerge 包来操作一些 docx 模板,当网站加载时,它在“来自 lxml.etree 导入元素”这一行上失败。

我已经尝试修改mailmerge.py文件中的导入命令无济于事。我已经在我的 virtualenv 内外安装了 lxml 和 mailmerge 包。我已经用谷歌搜索过这个网站和其他网站,但是当我尝试各种修复操作时,搜索结果要么不适用,要么没有解决问题。

这是我的项目 Apache 错误日志中的 sn-p:

Apache Error Log

这是我的 wsgi_windows.py 文件:

# execfile(activate_this, dict(__file__=activate_this))
exec(open(activate_this).read(),dict(__file__=activate_this))

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('D:/QR/qr_env/Lib/site-packages')




# Add the app's directory to the PYTHONPATH
sys.path.insert(0,'D:/QR')
sys.path.insert(1,'D:/QR/quality_review')

os.environ['DJANGO_SETTINGS_MODULE'] = 'quality_review.settings'
#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "quality_review.settings")
os.environ["DJANGO_SETTINGS_MODULE"] = "quality_review.settings"

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application 

这是项目在 vhosts.conf 文件中的条目:

<VirtualHost *:8082>
    ServerName ********** 
    WSGIPassAuthorization On
    ErrorLog "logs/quality_review.error.log"
    CustomLog "logs/quality_review.access.log" combined
    WSGIScriptAlias /  "D:\QR\quality_review\wsgi_windows.py"
    <Directory "D:\QR\quality_review">
        <Files wsgi_windows.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static "D:\QR\static"
    <Directory "D:\QR\static">
        Require all granted
    </Directory>  
    Alias /documents "D:\QR\documents"
    <Directory "D:\QR\documents">
        Require all granted
    </Directory>
</VirtualHost>

httpd.conf:

LoadFile "c:/users/rcs/appdata/local/programs/python/python37-32/python37.dll"
LoadModule wsgi_module "c:/users/rcs/appdata/local/programs/python/python37-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd"
WSGIPythonHome "c:/users/rcs/appdata/local/programs/python/python37-32"

这是来自主要 Apache 错误日志的最新 sn-p:

[Wed Jun 10 12:00:56.550356 2020] [mpm_winnt:notice] [pid 480:tid 560] AH00418: Parent: Created child process 5412
[Wed Jun 10 12:00:56.550356 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(430): AH00402: Parent: Sent the scoreboard to the child
[Wed Jun 10 12:00:56.878480 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(1719): AH00453: Child process is running
[Wed Jun 10 12:00:56.878480 2020] [wsgi:info] [pid 5412:tid 460] mod_wsgi (pid=5412): Python home c:/users/rcs/appdata/local/programs/python/python37.
[Wed Jun 10 12:00:56.878480 2020] [wsgi:info] [pid 5412:tid 460] mod_wsgi (pid=5412): Initializing Python.
[Wed Jun 10 12:00:56.894105 2020] [wsgi:info] [pid 5412:tid 460] mod_wsgi (pid=5412): Attach interpreter ''.
[Wed Jun 10 12:00:56.909730 2020] [wsgi:info] [pid 5412:tid 460] mod_wsgi (pid=5412): Imported 'mod_wsgi'.
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(344): AH00391: Child: Retrieved our scoreboard from the parent.
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 424 (0.0.0.0:8082) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket 0.0.0.0:8082
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 420 ([::]:8082) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 416 (0.0.0.0:8081) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 412 ([::]:8081) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 400 (0.0.0.0:8080) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(513): AH00408: Parent: Duplicating socket 408 ([::]:8080) and sending it to child process 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 480:tid 560] mpm_winnt.c(532): AH00411: Parent: Sent 6 listeners to child 5412
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket [::]:8082
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket 0.0.0.0:8081
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket [::]:8081
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket 0.0.0.0:8080
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(466): AH00403: Child: Waiting for data for listening socket [::]:8080
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] mpm_winnt.c(491): AH00407: Child: retrieved 6 listeners from parent
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 460] child.c(969): AH00352: Child: Acquired the start mutex.
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:notice] [pid 5412:tid 460] AH00354: Child: Starting 64 worker threads.
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1172] child.c(430): AH00334: Child: Accept thread listening on 0.0.0.0:8082 using AcceptFilter connect
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1180] child.c(430): AH00334: Child: Accept thread listening on 0.0.0.0:8080 using AcceptFilter connect
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1192] child.c(430): AH00334: Child: Accept thread listening on [::]:8080 using AcceptFilter connect
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1208] child.c(430): AH00334: Child: Accept thread listening on [::]:8081 using AcceptFilter connect
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1204] child.c(430): AH00334: Child: Accept thread listening on 0.0.0.0:8081 using AcceptFilter connect
[Wed Jun 10 12:00:56.909730 2020] [mpm_winnt:debug] [pid 5412:tid 1212] child.c(430): AH00334: Child: Accept thread listening on [::]:8082 using AcceptFilter connect

我不确定还需要哪些其他信息来提供帮助,但如果需要,我很乐意提供其他文件。

【问题讨论】:

  • 请分享您的 apache.conf LoadFile "***ython37.dll" 和 LoadModule wsgi_module "***\mod_wsgi.cp37-win_amd64.pyd" 中的相似行
  • 我已使用请求的信息编辑了我的帖子。感谢您的回复。
  • 你的windows系统是32位的?
  • 不,它是 64 位 Windows。
  • 你已经安装了32位版本的python37:/mod_wsgi.cp37-win32.pyd"

标签: python django apache mod-wsgi


【解决方案1】:

请卸载 32bits python37 版本并重新安装 64bits python37 版本并更新您的 apache conf:

LoadFile "***/python37.dll"
LoadModule wsgi_module "*****/mod_wsgi.cp37-win_amd64.pyd"

然后如果有任何错误,请分享所有的apache日志文件

请在您的 httpd.conf 文件中:设置:

LogLevel debug

看看你的日志文件,你能找到这些信息吗:

[Fri May 08 17:49:52.230167 2020] [mpm_winnt:notice] [pid 5560:tid 540] AH00455: Apache/2.4.43 (Win64) mod_wsgi/4.7.1 Python/3.7 configured -- resuming normal operations
[Fri May 08 17:49:52.231163 2020] [mpm_winnt:notice] [pid 5560:tid 540] AH00456: **Apache Lounge VS16 Server built**: Apr 21 2020 16:23:13
[Fri May 08 17:49:52.231163 2020] [core:notice] [pid 5560:tid 540] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Fri May 08 17:49:52.231163 2020] [core:debug] [pid 5560:tid 540] log.c(1568): AH02639: Using SO_REUSEPORT: no (0)
[Fri May 08 17:49:52.232165 2020] [mpm_winnt:notice] [pid 5560:tid 540] AH00418: Parent: Created child process 2860
[Fri May 08 17:49:52.232165 2020] [mpm_winnt:debug] [pid 5560:tid 540] mpm_winnt.c(430): AH00402: Parent: Sent the scoreboard to the child
[Fri May 08 17:49:52.561181 2020] [mpm_winnt:debug] [pid 2860:tid 180] mpm_winnt.c(1719): AH00453: Child process is running
[Fri May 08 17:49:52.561181 2020] [wsgi:info] [pid 2860:tid 180] **mod_wsgi (pid=2860): Python home c:/program files/python37.**
[Fri May 08 17:49:52.561181 2020] [wsgi:info] [pid 2860:tid 180] m**od_wsgi (pid=2860): Initializing Python.**
[Fri May 08 17:49:52.584179 2020] [wsgi:info] [pid 2860:tid 180] **mod_wsgi (pid=2860): Attach interpreter ''.**
[Fri May 08 17:49:52.588181 2020] [wsgi:info] [pid 2860:tid 180] **mod_wsgi (pid=2860): Imported 'mod_wsgi'.**

对于 WSGIPythonHome:

“用于在 Python 初始化时向 Python 指示其库文件的安装位置。”

我认为您的项目站点包位于:

【讨论】:

  • 我已将 32 位 python 和 Apache 替换为 64 位。我原来的两个站点在配置 Apache 后工作,但最新站点仍然给出相同的模块未找到错误。这是错误日志:link
  • 抱歉,您指的是什么路径?
  • 我在日志中没有找到apache启动的消息
  • httpd.conf 的路径:
  • Apache 正在启动,并成功地为其他站点提供服务。它只是无法加载有问题的网站。 httpd.conf 中的路径是我从 mod_wsgi 得到的路径,所以我相信它们是正确的。
猜你喜欢
  • 1970-01-01
  • 2012-07-14
  • 2016-06-15
  • 2019-11-13
  • 1970-01-01
  • 2014-05-16
  • 2021-11-17
  • 2013-07-01
  • 2016-12-09
相关资源
最近更新 更多