2016-09-20 75 views
0

我試圖在AWS AMI上運行一個應該使用OpenCV庫的簡單應用程序。我創建了一個虛擬機,並安裝了OpenCV。對於安裝,我遵循本教程http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/,似乎也可以,因爲我能夠運行該示例。AWS上的Opencv/Flask應用程序AMI

[Tue Sep 20 09:58:14.117753 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] Traceback (most recent call last): 
[Tue Sep 20 09:58:14.117778 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.wsgi", line 25, in <module> 
[Tue Sep 20 09:58:14.117822 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from app import app as application 
[Tue Sep 20 09:58:14.117831 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.py", line 13, in <module> 
[Tue Sep 20 09:58:14.117878 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from flask import (Flask, abort, flash, g, jsonify, make_response, render_template, request, session, url_for) 
[Tue Sep 20 09:58:14.117887 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/flask/__init__.py", line 19, in <module> 
[Tue Sep 20 09:58:14.117916 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from jinja2 import Markup, escape 
[Tue Sep 20 09:58:14.117923 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module> 
[Tue Sep 20 09:58:14.117951 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from jinja2.environment import Environment, Template 
[Tue Sep 20 09:58:14.117965 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module> 
[Tue Sep 20 09:58:14.118148 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from jinja2 import nodes 
[Tue Sep 20 09:58:14.118157 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module> 
[Tue Sep 20 09:58:14.118287 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from jinja2.utils import Markup 
[Tue Sep 20 09:58:14.118296 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module> 
[Tue Sep 20 09:58:14.118418 2016] [:error] [pid 15068] [remote 77.246.17.229:18121]  from markupsafe import Markup, escape, soft_unicode 
[Tue Sep 20 09:58:14.118436 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] ImportError: No module named markupsafe 

,但我查了所有的命令在虛擬機上安裝的模塊PIP凍結我得到如下:當我嘗試運行我的長頸瓶的應用程序,因爲我發現了以下錯誤,就會出現問題

click==6.6 
Flask==0.11.1 
itsdangerous==0.24 
Jinja2==2.8 
MarkupSafe==0.23 
numpy==1.11.1 
Werkzeug==0.11.11 

因此,MarkupSafe安裝並更新了最新版本。

於是開始思考這個問題可能是我的.wgsi文件或在httpd.conf 這裏app.wsgi:

import sys 
import site 
import os 

# Add virtualenv site packages 
site.addsitedir(os.path.join(os.path.dirname(__file__), '/var/www/flaskapp/env/lib/python2.7/site-packages')) 

#activate_this = '/var/www/flaskapp/env/bin/activate_this.py' 
#execfile(activate_this, dict(__file__=activate_this)) 

# Path of execution 
sys.path.insert(0,'/var/www/flaskapp') 

#import the app 
from app import app as application 

而這一次是在httpd.conf: 聽80

<VirtualHost *> 
     ServerName ec2... 
     WSGIDaemonProcess app threads=5 home=/var/www/flaskapp/ python-path=/var/www/flaskapp/env/lib/python2.7/site-packages threads=1 

     DocumentRoot /var/www/flaskapp 

     WSGIScriptAlias//var/www/flaskapp/app.wsgi 
     <Directory /var/www/flaskapp> 
       WSGIProcessGroup app 
       WSGIApplicationGroup %{GLOBAL} 
       Order deny,allow 
       Allow from all 
     </Directory> 
</VirtualHost> 

但我無法弄清楚這個問題。任何想法爲什麼我得到這個錯誤?

如果我試圖將我的app.wgsi引用到lib64而不是隻是lib,則錯誤將變爲:ImportError:numpy.core.multiarray無法導入。我檢查了lib和lib64中的differente站點包,並且我有這種配置:

lib: click-easy_install.pyc - itsdangerous.py - markerlib - setuptools - click-6.6-py2.7.egg-info - flask - itsdangerous.pyc - pip - setuptools-12.0.5.dist-info - cv2.so - Flask-0.11.1.dist-info - jinja2 - pip-6.0.8.dist-info - werkzeug - easy_install.py - itsdangerous-0.24-py2.7.egg - 信息 - Jinja2-2.8.dist - 信息 - 通過pkg_resources - WERKZEUG-0.11.11.dist-信息

而在lib64的我: markupsafe MarkupSafe-0.23-PY2。 7.egg-info numpy numpy-1.11.1-py2.7.egg-info

看來莫d_wsgi爲python 2.6.9配置,我使用python 2.7。這可能是問題嗎?

回答

0

你不能爲Python 2.6編譯mod_wsgi,並嘗試強制它使用Python 2.7的Python虛擬環境。您將需要卸載mod_wsgi並從二進制包或源代碼重新安裝,但是它是爲Python 2.7編譯的。這不是修改使用什麼版本的Python的配置選項。必須爲正確的Python版本進行編譯才能開始。