【问题标题】:ImportError: No module named bottle -- WSGI + python + apacheImportError: No module named bottle -- WSGI + python + apache
【发布时间】:2016-12-19 01:44:35
【问题描述】:

我试图通过 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
>>> 

更新:

我尝试进行“hello world”测试以查看 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 错误。

感谢任何帮助。

【问题讨论】:

  • 可能你没有文件夹权限
  • 哪个文件夹? @Raskayu
  • bottle.py 文件在哪里?从 shell 运行python 时获得的 Python 环境可能与网络服务器创建的环境不同。

标签: python apache amazon-web-services amazon-ec2 bottle


【解决方案1】:

尝试从您的目录中卸载瓶子,然后打开 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

【讨论】:

  • 已经尝试重新安装瓶子和重新安装 mod_wsgi -- 都没有成功...
猜你喜欢
  • 2016-12-23
  • 2017-03-31
  • 1970-01-01
  • 2015-11-11
  • 2015-09-10
  • 2011-04-08
  • 2016-08-09
  • 1970-01-01
  • 2017-02-10
相关资源
最近更新 更多