0
votes

I'm trying to run a simple app on AWS AMI that should use OpenCV library. I created a virtual machine and i installed OpenCV. For the installation I followed this tutorial http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/ and seems to be ok also because I able to run the example. The problem arises when I try to run my Flask-app because I'm getting the following error:

[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

but I checked all the installed modules on the virtual machine with the command pip freeze i get the following:

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

So MarkupSafe is installed and updated a the last version.

So started thinking the problem could be in my .wgsi file or in the httpd.conf Here 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

And this one is the httpd.conf: Listen 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>

But I'm not able to figure out the problem. Any idea about why I get this error?

If I try to reference my app.wgsi to lib64 instead of just lib the error becomes : ImportError: numpy.core.multiarray failed to import. I checked the differente site-packages present in lib and lib64 and I have this configuration:

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-info - Jinja2-2.8.dist-info - pkg_resources - Werkzeug-0.11.11.dist-info

while in lib64 I have: markupsafe MarkupSafe-0.23-py2.7.egg-info numpy numpy-1.11.1-py2.7.egg-info

It seems the mod_wsgi is configured for python 2.6.9 and I'm using python 2.7. could that be the problem?

1

1 Answers

0
votes

You cannot take a mod_wsgi compiled for Python 2.6 and try and force it to use a Python virtual environment using Python 2.7. You will need to uninstall mod_wsgi and reinstall it from a binary package or source, but where it is compiled for Python 2.7. It is not a configuration option to change what version of Python is used. It must be compiled for the correct Python version to start with.