Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running django python 3.4 on mod_wsgi with apache2

Hi I am getting the error below when going to the website url on ubuntu server 14.10 running apache 2 with mod_wsgi and python on django.

My django application uses python 3.4 but it seems to be defaulting to python 2.7, I am unable to import image from PIL and AES from pycrypto.

ImportError at /
cannot import name _imaging
Request Method: GET
Request URL:
Django Version: 1.7.3
Exception Type: ImportError
Exception Value:
cannot import name _imaging
Exception Location: /usr/local/lib/python3.4/dist-packages/PIL/Image.py in , line 63
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/var/www/blabla',
'/usr/local/lib/python3.4/dist-packages']

like image 575
user3823837 Avatar asked Jan 19 '15 06:01

user3823837


People also ask

Can I use Django with Apache?

Django will work with any version of Apache which supports mod_wsgi. The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi. You'll probably want to start with the installation and configuration documentation.

What is mod_wsgi in Apache?

mod_wsgi is an Apache HTTP Server module by Graham Dumpleton that provides a WSGI compliant interface for hosting Python based web applications under Apache. As of version 4.5. 3, mod_wsgi supports Python 2 and 3 (starting from 2.6 and 3.2).

Does Django support ASGI?

As well as WSGI, Django also supports deploying on ASGI, the emerging Python standard for asynchronous web servers and applications.

How do I use WSGI in Django?

Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.


1 Answers

I believe that mod_wsgi is compiled against a specific version of python, so you need a py3.4 version of mod_wsgi. You may be able to get one from your os's package repository or you can build one without too much drama. From memory you'll need gcc and python-dev packages (python3-dev?) to build.

OK, quick google, for ubuntu 14.10: sudo apt-get install libapache2-mod-wsgi-py3 should install a py3 version of mod_wsgi (will probably want to remove the existing py2 version).

Adding a shebang line won't do any good as the python interpreter is already loaded before the wsgi.py script is read.

like image 125
Adam Kerz Avatar answered Nov 15 '22 03:11

Adam Kerz