简体   繁体   English

使用pyenv运行mod_wsgi

[英]Run mod_wsgi with pyenv

I'm trying to run a python web app on Apache server. 我正在尝试在Apache服务器上运行python网络应用。 I have installed mod_wsgi: sudo apt-get install libapache2-mod-wsgi . 我已经安装了mod_wsgi: sudo apt-get install libapache2-mod-wsgi

This is my site config file: 这是我的网站配置文件:

<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>

However, when trying to access the web app, I get "Internal server error". 但是,当尝试访问Web应用程序时,出现“内部服务器错误”。 This is the error from logs: 这是来自日志的错误:

[Mon Mar 12 13:34:04.054636 2018] [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' cannot be loaded as Python module. [2018年3月12日星期一13:34:04.054636] [wsgi:错误] [pid 6762:tid 139768980616960] [远程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): Exception occurred processing WSGI script '/home/user/API/config_files/myservice.wsgi.py'. [2018年3月12日星期一13:34:04.054665] [wsgi:error] [pid 6762:tid 139768980616960] [远程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 (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 [2018年3月12日星期一13:34:04.054693 2018年] [wsgi:错误] [pid 6762:tid 139768980616960] [远程10.10.30.13:34438]追溯(最近一次拨打电话为最后):[星期一3月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:error] [pid 6762:tid 139768980616960] [远程10.10.30.13:34438]从pathlib导入路径[Mon Mar 12 13:34:04.054775 2018] [wsgi:error] [pid 6762:tid 139768980616960] [远程10.10.30.13:34438] ImportError: 没有名为pathlib的模块

I have checked the pyenv python installation, and it has the pathlib module installed. 我已经检查了pyenv python安装,并安装了pathlib模块。 This means that probably, not the right version of Python is being used. 这意味着可能未使用正确版本的Python。 How can I check which Python version is being used? 如何检查使用的是哪个Python版本? Did I set the python-home property incorrectly? 我是否正确设置了python-home属性?

You can't use system packaged version of mod_wsgi with a pyenv environment. 您不能在pyenv环境中使用mod_wsgi的系统打包版本。 It is necessary for mod_wsgi to be compiled for the specific Python installation/version being used. 必须针对所使用的特定Python安装/版本编译mod_wsgi。 When using pyenv it is a separate Python installation, not the system Python that is being used. 使用pyenv时,它是单独的Python安装,而不是正在使用的系统Python。 You should use the pip install method for installing mod_wsgi compiled for Python installation created by pyenv. 您应该使用pip install方法安装为pyenv创建的Python安装而编译的mod_wsgi。 Do make sure that when you had pyenv install Python that shared libraries were enabled. 确保在安装pyenv的Python后启用了共享库。

IOW, uninstall system packaged version of mod_wsgi and then use pip install method to install mod_wsgi and configure Apache to use it. IOW,卸载系统打包的mod_wsgi版本,然后使用pip install方法安装mod_wsgi并配置Apache以使用它。 See: 看到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM