我想在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>
但是,当尝试访问Web应用程序时,我得到“内部服务器错误”。这是来自日志的错误:
[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/www.example.com”加载为Python模块。myservice.wsgi.py处理WSGI脚本“/home/user/API/config_files/www.example.com”时发生异常。[Mon Mar 12 13:34:04.054693 2018][wsgi:error][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] Traceback(most recent call last):[3月12日星期一13:三十四:04.054717 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] File "/home/user/API/config_files/www.example.com ",line 6,in [Mon Mar 12 13:三十四:04.054752 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438]从pathlib导入路径[Mon Mar 12 13:三十四:04.054775 2018][wsgi:错误][pid 6762:tid 139768980616960][remote 10.10.30.13:34438] ImportError:* * 没有名为pathlib的模块**myservice.wsgi.py '. [Mon Mar 12 13:34:04.054693 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] Traceback (most recent call last): [Mon Mar 12 13:34:04.054717 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] File "/home/user/API/config_files/myservice.wsgi.py ", line 6, in [Mon Mar 12 13:34:04.054752 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] from pathlib import Path [Mon Mar 12 13:34:04.054775 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] ImportError:No module named pathlib
我已经检查了pyenv python安装,它安装了pathlib模块。这意味着可能没有使用正确的Python版本。如何查看使用的Python版本?我是否错误地设置了python-home
属性?
1条答案
按热度按时间jei2mxaa1#
你不能在pyenv环境中使用mod_wsgi的系统打包版本。mod_wsgi必须针对所使用的特定Python安装/版本进行编译。当使用pyenv时,它是一个单独的Python安装,而不是正在使用的系统Python。你应该使用
pip install
方法来安装为pyenv创建的Python安装编译的mod_wsgi。请确保在安装pyenv时启用了共享库。IOW,卸载系统打包版本的mod_wsgi,然后使用
pip install
方法安装mod_wsgi并配置Apache使用它。参见:具体来说,请参阅
Connecting into Apache installation
部分,了解如何将pip安装的mod_wsgi加载到Apache中。即修改/etc/apache2/mods-available/wsgi.load
中的路径,使其指向虚拟环境中的mod_wsgi-<version>.so
文件。