【问题标题】:Run mod_wsgi with pyenv使用 pyenv 运行 mod_wsgi
【发布时间】:2018-08-21 01:27:06
【问题描述】:

我正在尝试在 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>

但是,在尝试访问网络应用程序时,我收到“内部服务器错误”。这是日志中的错误:

[2018 年 3 月 12 日星期一 13:34:04.054636] [wsgi:error] [pid 6762:tid 139768980616960] [remote 10.10.30.13:34438] mod_wsgi (pid=6762): Target WSGI script '/home/user/ API/config_files/myservice.wsgi.py' 不能作为 Python 模块加载。 [2018 年 3 月 12 日星期一 13:34:04.054665] [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'。 [2018 年 3 月 12 日星期一 13:34:04.054693] [wsgi:error] [pid 6762:tid 139768980616960] [远程 10.10.30.13:34438] 回溯(最近一次通话最后): [2018 年 3 月 12 日星期一 13:34:04.054717] [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] 来自 pathlib 导入路径 [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 属性?

【问题讨论】:

    标签: python apache mod-wsgi pyenv


    【解决方案1】:

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

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

    【讨论】:

    • 是的,但是在我的情况下,如何让 mod_wsgi 使用 pyenv 环境而不是 Redhat 附带的系统?该系统已全局安装 3.6,但我正在尝试将 3.9 与 pyenv 一起使用。谢谢。
    猜你喜欢
    • 2020-10-11
    • 2020-10-11
    • 2018-09-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    相关资源
    最近更新 更多