我正在尝试在 Apache 服务器上运行 python Web 应用程序。我已经安装了 mod_wsgi:sudo apt-get install libapache2-mod-wsgi
.
这是我的站点配置文件:
<virtualhost *:80>
ServerName 192.168.60.144
WSGIDaemonProcess myapp.dev processes=1 threads=1 python-home="/home/user/.pyenv/versions/3.6.1" python-path="/home/user/API" home='/home/user/API'
WSGIProcessGroup myapp.dev
WSGIScriptAlias / /home/user/API/config_files/myservice.wsgi.py
<Directory /home/user/API>
Order allow,deny
Allow from all
</Directory>
DocumentRoot /home/user/API/myservice/testdir
<Directory />
AllowOverride None
Require all granted
</Directory>
</virtualhost>
但是,当尝试访问网络应用程序时,我收到“内部服务器错误”。这是日志中的错误:
[Mon Mar 12 13:34:04.054636 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] mod_wsgi (pid=6762): 目标 WSGI 脚本'/home/user/API/config_files /myservice.wsgi.py' 无法作为 Python 模块加载。
[Mon Mar 12 13:34:04.054665 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] mod_wsgi (pid=6762): 处理 WSGI 脚本'/home/user/API 时发生异常/config_files/myservice.wsgi.py'。
[Mon Mar 12 13:34:04.054693 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] 回溯(最近一次调用):
[2018 年 3 月 12 日星期一 13:34:04.054717 2018] [wsgi:error] [pid 6762:tid 139768980616960] [远程 10.10.30.13:34438] 文件“/home/user/API/config_files/myservice.wsgi.py”,行6、在
[2018 年 3 月 12 日星期一 13:34:04.054752] [wsgi:error] [pid 6762:tid 139768980616960] [远程 10.10.30.13:34438] from pathlib import Path
[2018 年 3 月 12 日星期一 13:34:04.054775] [wsgi:error] [pid 6762:tid 139768980616960] [远程 10.10.30.13:34438] ImportError:没有名为 pathlib 的模块
我检查了 pyenv python 安装,它安装了 pathlib 模块。这意味着可能使用的 Python 版本不正确。如何检查正在使用哪个 Python 版本?我是否设置了python-home
属性错误?
您不能在 pyenv 环境中使用 mod_wsgi 的系统打包版本。需要针对正在使用的特定 Python 安装/版本来编译 mod_wsgi。使用 pyenv 时,它是一个单独的 Python 安装,而不是正在使用的系统 Python。您应该使用pip install
安装由 pyenv 创建的为 Python 安装编译的 mod_wsgi 的方法。请确保当您使用 pyenv 安装 Python 时启用了共享库。
- https://github.com/pyenv/pyenv/issues/392 https://github.com/pyenv/pyenv/issues/392
IOW,卸载系统打包版的mod_wsgi然后使用pip install
安装 mod_wsgi 并配置 Apache 以使用它的方法。看:
- https://pypi.python.org/pypi/mod_wsgi https://pypi.python.org/pypi/mod_wsgi
特别是,请参阅Connecting into Apache installation
有关如何将 pip 安装的 mod_wsgi 加载到 Apache 的部分。即修改路径/etc/apache2/mods-available/wsgi.load
指向mod_wsgi-<version>.so
虚拟环境中的文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)