Search code examples
pythondjangoapachemod-wsgiubuntu-server

Django Apache wsgi changes python version


I've installed my Django app on an Ubuntu server with Apache2.4.7 and configured it to use py3.5.2 from a virtual environment.

However, from what I can see in the errors, it's starting at 3.5 and defaulting to 3.4.

Please explain why this is happening:

/var/www/venv/lib/python3.5/site-packages
/usr/lib/python3.4

See the full error below:

SyntaxError at /

invalid syntax (forms.py, line 2)

Request Method:     GET
Request URL:    http://intranet.example.com/
Django Version:     1.10.1
Exception Type:     SyntaxError
Exception Value:    

invalid syntax (forms.py, line 2)

Exception Location:     /var/www/intranet/formater/views.py in <module>, line 7
Python Executable:  /usr/bin/python3
Python Version:     3.4.3
Python Path:    

['/var/www/intranet',
 '/var/www/venv/lib/python3.5/site-packages',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/usr/lib/python3.4/lib-dynload',
 '/usr/local/lib/python3.4/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/var/www/intranet',
 '/var/www/intranet/venv/lib/python3.5/site-packages']

Here's my apache2.conf file:

WSGIScriptAlias / /var/www/intranet/intranet/wsgi.py
#WSGIPythonPath /var/www/intranet/:/var/www/intranet/venv/lib/python3.5/site-packages

WSGIDaemonProcess intranet.example.com python-path=/var/www/intranet:/var/www/venv/lib/python3.5/site-packages
WSGIProcessGroup intranet.example.com

<Directory /var/www/intranet/intranet>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

What am I doing wrong here?


Solution

  • The mod_wsgi module for Apache is compiled for a specific Python version. You cannot make it run using a different Python version by pointing it at a Python virtual environment for a different Python version. This is cleared mentioned in the mod_wsgi documentation about use of Python virtual environments at:

    The only way you can have mod_wsgi run as Python 3.5, if it was original compiled for Python 3.4, is to uninstall that version of mod_wsgi and build/install a version of mod_wsgi compiled for Python 3.5.