首页 文章

用pyenv运行mod_wsgi

提问于
浏览
0

我正在尝试在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 / 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] Traceback(最近一次电话 Session ):[Mon Mar 12 13:34:04.054717 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438]文件“/home/user/API/config_files/myservice.wsgi.py”,第6行,[Mon Mar 12 13:34: 04.054752 2018] [wsgi:错误] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438]来自pathlib导入路径[Mon Mar 12 13:34:04.054775 2018] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] ImportError:没有名为pathlib的模块

我检查了pyenv python安装,它安装了pathlib模块 . 这意味着可能没有使用正确版本的Python . 如何查看正在使用的Python版本?我是否错误地设置了 python-home 属性?

1 回答

  • 1

    您不能将系统打包版本的mod_wsgi与pyenv环境一起使用 . 必须为正在使用的特定Python安装/版本编译mod_wsgi . 使用pyenv时,它是一个单独的Python安装,而不是正在使用的系统Python . 您应该使用 pip install 方法安装为pyenv创建的Python安装编译的mod_wsgi . 确保在pyenv安装Python时启用了共享库 .

    IOW,卸载系统打包的mod_wsgi版本,然后使用 pip install 方法安装mod_wsgi并配置Apache使用它 . 看到:

相关问题