Python 在EC2 ubuntu上的Flask中导入熊猫(和其他模块)会出现错误

Python 在EC2 ubuntu上的Flask中导入熊猫(和其他模块)会出现错误,python,amazon-ec2,pandas,flask,Python,Amazon Ec2,Pandas,Flask,我有一个Ubuntu12.04.3 LTS EC2实例(我安装了apache、java等),还有一个Anaconda/Python的工作版本 我还设置了flask(在apache后面运行)并设置了一个虚拟主机。我为flask设置了以下目录: 我的init.py文件非常简单: from __future__ import division import string import datetime import json import xml.etree.ElementTree as ET

我有一个Ubuntu12.04.3 LTS EC2实例(我安装了apache、java等),还有一个Anaconda/Python的工作版本

我还设置了flask(在apache后面运行)并设置了一个虚拟主机。我为flask设置了以下目录:

我的init.py文件非常简单:

from __future__ import division

import string
import datetime
import json
import xml.etree.ElementTree as ET

from flask import Flask, jsonify
from flask import abort

#import pandas as pd
#import requests

app = Flask(__name__)

@app.route("/")

def hello():
    return "test6"

if __name__ == "__main__":
    app.run()
然后,在运行pythoninit.py之后,当我到达我的EC2实例公共地址时,一切正常,我得到了预期的消息“test6”

现在我取消对panda或requests的注释,服务器/烧瓶端的一切都可以正常运行:

 * Running on http://127.0.0.1:5000/
当我跑步时:

curl http://127.0.0.1:5000/
我得到了我所期望的(即“test6”)

但当我导航到相同的EC2公共URL时,我得到:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@mywebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/2.2.22 (Ubuntu) Server at ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com Port 80
有人知道发生了什么吗?我只是导入了两个模块,我可以从命令行版本的python导入它们(而且整个设置在我的mac上本地运行良好)

可能是因为它的小实例内存不足

提前感谢您的帮助

编辑:只需查看apache服务器日志(error.log):

[Sun Nov 03 21:48:56 2013][notice]Apache/2.2.22(Ubuntu)mod_wsgi/3.3 Python/2.7.3已配置--恢复正常操作
[Sun Nov 03 21:49:51 2013][通知]已捕获到SIGTERM,正在关闭
[Sun Nov 03 21:49:52 2013][warn]mod_wsgi:为Python/2.7.2+编译。
[Sun Nov 03 21:49:52 2013][warn]mod_wsgi:Runtime using Python/2.7.3。
[Sun Nov 03 21:49:52 2013][注意]Apache/2.2.22(Ubuntu)mod_wsgi/3.3 Python/2.7.3已配置--恢复正常操作
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]mod_wsgi(pid=6874):无法将目标wsgi脚本“/var/www/microblog/microblog.wsgi”作为Python模块加载。
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]mod_wsgi(pid=6874):处理wsgi脚本'/var/www/microblog/microblog.wsgi'时发生异常。
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]回溯(最近一次通话):
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]文件“/var/www/microblog/microblog.wsgi”,第7行,在
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]从应用程序导入应用程序作为应用程序
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]文件“/var/www/microblog/app/_init__.py”,第11行,在
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]将熊猫作为pd导入
[Sun Nov 03 21:50:02 2013][error][client xx.xxx.xxx.xx]导入错误:没有名为pandas的模块
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]mod_wsgi(pid=6873):无法将目标wsgi脚本“/var/www/microblog/microblog.wsgi”作为Python模块加载。
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]mod_wsgi(pid=6873):处理wsgi脚本'/var/www/microblog/microblog.wsgi'时发生异常。
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]回溯(最近一次通话):
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]文件“/var/www/microblog/microblog.wsgi”,第7行,在
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]从应用程序导入应用程序作为应用程序
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]文件“/var/www/microblog/app/_init__.py”,第11行,在
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]将熊猫作为pd导入
[Sun Nov 03 21:50:03 2013][error][client xx.xxx.xxx.xx]导入错误:没有名为pandas的模块

能否启用调试器以获取堆栈跟踪?只需将
debug=True
作为参数传递给
app.run()
。这样做-看起来没有问题-我感觉这与“sudo-apt-get-install-libapache2 mod wsgi”有关-只需查看apache服务器日志并试图找出它…只需将日志粘贴到问题中-日志非常清晰,您没有
pandas
。我认为这不太正确-我有pandas(因为我安装了Anaconda),但Apache没有指向正确的python版本和模块…请将解决方案添加到您的书中(一旦我找到解决方案)-我期待着您的书!对此有任何决议吗?我也面临同样的错误。我有熊猫。
[Sun Nov 03 21:48:56 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sun Nov 03 21:49:51 2013] [notice] caught SIGTERM, shutting down
[Sun Nov 03 21:49:52 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sun Nov 03 21:49:52 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sun Nov 03 21:49:52 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx] mod_wsgi (pid=6874): Target WSGI script '/var/www/microblog/microblog.wsgi' cannot be loaded as Python module.
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx] mod_wsgi (pid=6874): Exception occurred processing WSGI script '/var/www/microblog/microblog.wsgi'.
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx] Traceback (most recent call last):
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx]   File "/var/www/microblog/microblog.wsgi", line 7, in <module>
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx]     from app import app as application
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx]   File "/var/www/microblog/app/__init__.py", line 11, in <module>
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx]     import pandas as pd
[Sun Nov 03 21:50:02 2013] [error] [client xx.xxx.xxx.xx] ImportError: No module named pandas
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx] mod_wsgi (pid=6873): Target WSGI script '/var/www/microblog/microblog.wsgi' cannot be loaded as Python module.
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx] mod_wsgi (pid=6873): Exception occurred processing WSGI script '/var/www/microblog/microblog.wsgi'.
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx] Traceback (most recent call last):
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx]   File "/var/www/microblog/microblog.wsgi", line 7, in <module>
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx]     from app import app as application
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx]   File "/var/www/microblog/app/__init__.py", line 11, in <module>
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx]     import pandas as pd
[Sun Nov 03 21:50:03 2013] [error] [client xx.xxx.xxx.xx] ImportError: No module named pandas