Running django python 3.4 on mod_wsgi with apache2

Hi, I get the error message below when going to url site on ubuntu 14.10 server running apache 2 with mod_wsgi and python on django.

My django application uses python 3.4, but it doesn't seem to work with python 2.7, I cannot import an 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:
unable to 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']

+6
source share
3 answers

I believe mod_wsgi is compiled against a specific version of python, so you need a version of mod_wsgi py3.4. Perhaps you can get it from your os package repository, or you can create it without too much drama. From memory, you will 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 the mod_wsgi py3 version (you might want to uninstall the existing py2 version).

Adding a shebang line will not do any good since the python interpreter is already loaded before reading the wsgi.py script.

+9
source

From what I see here, your application uses a py2 interpreter with compiled py3 modules that does not work.

The only possible solution that comes to my mind is to add or change the first line of manage.py to #!/usr/bin/python3 . This will tell the script to be interpreted with py3.

Further in the list of assumptions there will be an incorrect configuration in the * .wsgi file or apache config, depending on what you are using.

0
source

Thanks guys,

I really fixed this problem this morning by running make install mod_wsgi with .configure, pointing to python3.4.

I think you were right Adam.

0
source

Source: https://habr.com/ru/post/981197/


All Articles