Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am setting up a flask application on and Ubuntu 12.04.3 LTS EC2 instance and everything seemed to be working well (i.e. I could get to the webpage via the publicly available url) until I tried to import a module (e.g. numpy) and realised the apache python differs from the one I used to compile the mod_wsgi and also the one I am using

I am running apache2.

The apache2 logs show the warnings (specifically the last line shows the path hasnt changed):

[warn] mod_wsgi: Compiled for Python/2.7.5.
[warn] mod_wsgi: Runtime using Python/2.7.3.
[warn] mod_wsgi: Python module path '/usr/lib/python2.7/:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib$

I have tried to set the path in my virtual host conf (my python is located in /home/ubuntu/anaconda/bin along with all of the other libraries):

WSGIPythonHome /home/ubuntu/anaconda
WSGIPythonPath /home/ubuntu/anaconda

<VirtualHost *:80>
                ServerName xx-xx-xxx-xxx-xxx.compute-1.amazonaws.com
                ServerAdmin admin@mywebsite.com
                WSGIScriptAlias / /var/www/microblog/microblog.wsgi
                <Directory /var/www/microblog/app/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/microblog/app/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

But I still get the warnings and the apache python path hasnt changed - where do I need to put the relevant directives to point apache at my python version and modules (e.g. scipy, numpy etc)?

Separately, could I have avoided this using virtual environments?

Thanks in advance.

EDIT #1:

I have run:

>>> import sys
>>> print sys.prefix

To get:

/home/ubuntu/anaconda

And running ldd mod_wsgi.so with set/unset LD_LIBRARY_PATH gives the same symlink

libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007f13ca1c1000)

Which is the system version of python NOT the one I want and NOT the one I compiled mod_wsgi when I ran:

./configure --with-python=/home/ubuntu/anaconda/bin/python2.7
share|improve this question

1 Answer 1

The difference in patch level revision doesn't usually matter and is explained in:

More important is what is the value of sys.prefix when scripts are run under mod_wsgi.

And what Python shared library the mod_wsgi.so file is actually using and whether you compiled it correctly to ensure it will pick up the alternate shared library.

If it truly isn't picking up the correct shared library, then the mismatch can be an issue and you need to recompile mod_wsgi.

Read through the documentation and perform the checks on your installation explained there and take the action described there as necessary.

share|improve this answer
    
Hey Graham, thanks for the above - just went through the last 2 links - and edited my question. Now not sure what to do though as I compiled mod_wsgi with the python version I wanted. Do I need to rebuild it or change the apache path? How do I change the apache path? –  one Nov 4 '13 at 8:51
    
Did you temporarily set LD_RUN_PATH as indicated when you were rebuilding mod_wsgi so the correct library directory was embedded in mod_wsgi? –  Graham Dumpleton Nov 5 '13 at 3:21
    
We ended up solving this by using Nginx/Gunicorn/Supervisord... –  one Nov 5 '13 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.