I have a website running on apache-python2(virtualenv)-flask stack on Arch linux server. It seems that wsgi application is not picking up the python from virtualenv, and instead uses system's python.
web/test.py
import sys
print(sys.version)
Result in: error_log
3.4.3 (default, Mar 25 2015, 17:13:50)
The default python on the server is
$ python --version
Python 3.4.3
The virtual environment I intend to use has python2
$ virtualenv -p /usr/bin/python2.7 flask
$ source flask/bin/activate
$ python --version
Python 2.7.10
The virtualhost apache file: /etc/httpd/conf/vhosts/msw.com
<VirtualHost *:80>
ServerName msw.com
ServerAlias www.msw.com
ServerAdmin webmaster@localhost
WSGIDaemonProcess msw user=live group=live threads=5 python-path=/home/live/msw/flask/lib/python2.7/site-packages
WSGIScriptAlias / /home/live/msw/msw.wsgi
<Directory /home/live/msw>
#Header set Access-Control-Allow-Origin "*"
WSGIScriptReloading On
WSGIProcessGroup msw
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The wsgi file: /home/live/msw/msw.wsgi
import sys
activate_this = '/home/live/msw/flask/bin/activate_this.py'
#execfile(activate_this, dict(__file__=activate_this))
with open(activate_this) as f:
code = compile(f.read(), activate_this, 'exec')
exec(code, dict(__file__=activate_this))
sys.path.insert(0, '/home/live/msw/web')
sys.path.insert(0, '/home/live/msw')
from web import msw as application
Why is mod_wsgi not picking up virtualenv's python? What am I doing wrong?
I eventually figured it out. The official arch-linux documentation is a bit confusing, mod_wsgi. It tries to imply that mod_wsgi installation will work for both Python2/3. However, mod_wsgi still ends up using system's Python3. I solved the problem by installing mod_wsgi2 which is specific to Python2.
pacman -S mod_wsgi2