我试图通过WSGI在我的apache Amazon EC2服务器上运行一个瓶子应用程序,我一直收到这个错误:
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] File "/var/www/html/website/app.wsgi", line 5, in <module>
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] import bottle
[Fri Aug 12 06:15:13 2016] [error] [client 72.219.147.5] ImportError: No module named bottle
当我安装mod_wsgi时,使用了它:
mod_wsgi-python26-3.2-6.11.amzn1.x86_64
这是我的app.wsgi文件
import os, sys
sys.path.insert(0, "/var/www/html/website")
import bottle
import app
application = bottle.default_app()
这是我的httpd.conf:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *>
ServerName website.website.me
DocumentRoot /var/www/html/website
WSGIDaemonProcess website threads=5
WSGIScriptAlias / /var/www/html/website/app.wsgi
<Directory "/var/www/html/website">
WSGIProcessGroup website
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
这是WSGI的版本(来自我的错误日志):
[Fri Aug 12 06:15:11 2016] [notice] Apache/2.2.31 (Unix) DAV/2 PHP/5.3.29 mod_wsgi/3.2 Python/2.6.9 configured -- resuming normal operations
但如果我运行python -V
,我会得到Python 2.7.10
。
此外,我知道瓶子安装正确,因为当我执行以下操作时,没有错误:
$ python
>>>import bottle #no import error
>>>
更新
我试过做一个&#34;你好世界&#34;测试wsgi是否正常工作:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
它有效,所以问题不在于WSGI。
这就是我的app.py文件中的内容:
from bottle import route, run, template, static_file, request
import main
template = """<html>
<head><title>Home</title></head>
<body>
<h1>Upload a file</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
Category: <input type="text" name="category" />
Select a file: <input type="file" name="upload1" />
Select a file: <input type="file" name="upload2" />
<input type="submit" value="Start upload" />
</form>
</body>
</html>"""
@route('/')
def index():
return template
如果我执行python app.py
,则没有错误。只是当我刷新website.website.me时出现500错误。
感谢任何帮助。
答案 0 :(得分:0)
尝试从您的目录中卸载瓶子,然后打开cmd并以管理员的身份运行它并输入pip install bottle并自行查看......
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>pip install bottle
Collecting bottle
Using cached bottle-0.12.9.tar.gz
Building wheels for collected packages: bottle
Running setup.py bdist_wheel for bottle ... done
Stored in directory: C:\Users\hkpra\AppData\Local\pip\Cache\wheels\6e\87\89\f7ddd6721f4a208d44f2dac02f281b2403a314dd735d2b0e61
Successfully built bottle
Installing collected packages: bottle
Successfully installed bottle-0.12.9