我想将python 3.5与瓶子和apache一起使用。
但是当我从浏览器访问adapter.wsgi时,
内部服务器错误
▼error_log
[error] ImportError:没有名为os的模块
[error] ImportError:没有名为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
答案 0 :(得分:1)
在终端中使用此命令,将python3用作所有与python相关的工作的默认值
alias python='/usr/bin/python3'
如果发生权限错误,您可以在开头使用sudo
答案 1 :(得分:1)
您的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
的配置给人。参见: