ImportError: No module named bottle. Python3.5.1

ImportError: No module named bottle. Python3.5.1

我想将 python 3.5 与 bottle 和 apache 一起使用。

但是当我从浏览器访问adapter.wsgi时,

Internal Server Error

▼error_log

[error] ImportError: No module named os

[error] ImportError: No module named bottle


应用程序

▼/etc/httpd/conf.d/wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so

WSGIPythonHome /opt/rh/rh-python35/root/usr/bin/python3

<FilesMatch \.wsgi$>
    SetHandler wsgi-script
    Options +ExecCGI
</FilesMatch>

<FilesMatch \.py$>
    SetHandler wsgi-script
    Options +ExecCGI
</FilesMatch>

▼adapter.wsgi

# -*- coding:utf-8 -*-
import sys, os
dirpath = os.path.dirname(os.path.abspath(__file__))
sys.path.append(dirpath)
os.chdir(dirpath)
import bottle
import index
application = bottle.default_app()

▼index.py

# -*- coding:utf-8 -*-
from bottle import route, run, template
from bottle import TEMPLATE_PATH

@route('/')
def index():
    return "HELLO WORLD!"

if __name__ == '__main__':
    run(host='hogetest.com', port=80, debug=True, reloader=True)

现状

$ python -V     

Python 3.5.1

$ which python  

alias python='/opt/rh/rh-python35/root/usr/bin/python3'

    /opt/rh/rh-python35/root/usr/bin/python3

在您的终端中使用此命令将 python3 作为所有 python 相关工作的默认设置

alias python='/usr/bin/python3'

如果出现权限错误可以在开头使用sudo

您的 WSGIPythonHome 指令开头是错误的。尝试改用:

WSGIPythonHome /opt/rh/rh-python35/root/usr

参数应与 sys.prefix 用于 Python 安装的参数相同。

使用 SCL Python 版本可能会导致其他复杂性。

如果单独这样做还不行,请找出 Python 共享库的 .so 的完整路径并使用:

LoadFile /opt/rh/rh-python35/root/usr/lib/libpython3.5.so
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/rh/rh-python35/root/usr

更改 LoadFile 指令以匹配共享库的完整路径。它可以改用名称 libpython3.5m.so.

根据您从哪里获得 mod_wsgi.so 文件,即使那样也可能不起作用。如果那是来自系统 mod_wsgi 包,那么它将不会针对 SCL Python 版本进行编译。在这种情况下,您将不得不卸载系统 mod_wsgi 软件包并从源代码自行编译 mod_wsgi,最好使用 pip install 方法,然后使用 mod_wsgi-express module-config 的配置给。参见: