9

I have a Django 1.5, Python 2.7 site running under Apache with mod_wsgi on a CentOS 6.4 server.

I have rebuilt this site using Django 1.6 and Python 3.3. Deploying it to the same server and changing the paths in httpd.conf I get the subject error. This new install works as expected using ./manage.py runserver.

Here are the two WSGI definitions from httpd.conf:

WSGIScriptAlias / /home/ccdgen/CCDGEN2/apache/wsgi.py
WSGIPythonPath         /home/ccdgen/CCDGEN2/ccdgen/ccdgen:/home/ccdgen/CCDGEN2/ccdgen:/home/ccdgen/CCDGEN2/lib/python3.3/site-packages
<Directory /home/ccdgen/CCDGEN2/ccdgen>
   <Files wsgi.py>
     Order allow,deny
     Allow from all
   </Files>
</Directory>

#WSGIScriptAlias /ccdgen /home/ccdgen/CCDGEN/apache/wsgi.py
#WSGIPythonPath /home/ccdgen/CCDGEN/mlhim/ccdgen:/home/ccdgen/CCDGEN/mlhim:/home/ccdgen/CCDGEN/lib/python2.7/site-packages
#<Directory /home/ccdgen/CCDGEN/mlhim>
#   <Files wsgi.py>
#     Order allow,deny
#     Allow from all
#   </Files>
#</Directory>

The wsgi.py file is the same on both installations:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mlhim.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Any ideas? Obvious oversights? Thanks

Tim Cook
  • 655
  • 1
  • 8
  • 18

4 Answers4

11

I had this problem recently:

ImproperlyConfigured: Error loading psycopg2 module: No module named _psycopg

... and this command was the answer:

sudo apt-get install libapache2-mod-wsgi-py3

Reference:

http://python.6.x6.nabble.com/ImproperlyConfigured-Error-loading-psycopg2-module-No-module-named-psycopg-td5044145.html

nicorellius
  • 3,715
  • 4
  • 48
  • 79
4

The problem was that mod_wsgi was compiled for Python 2.7 and it needed to be recompiled for Python 3.3. I did not find a new mod_wsgi available anywhere as a package so I recompiled it.

Since Python 3 is an alternate install on CentOS 6.4 .configure had a difficult time producing a good Makefile, even passing the --with-python option. I needed to edit Makefile a bit after getting the information from python3.3-config --cflags and also with --ldflags options.

HTH someone in the future.

Tim Cook
  • 655
  • 1
  • 8
  • 18
  • 1
    Can you plz explain what exactly did you do? – Ghasem Jan 11 '15 at 17:18
  • It was over a year ago so I do not recall the step by step process. But you will need to recompile Python on CentOS and read up on cflags and ldflags because the Makefile needs to be edited. I eventually moved the DB that requires CentOS/RHE to the cloud and went back to Ubuntu Server for my Django app. IMO, modern Python on development and use on CentOS is a no go. – Tim Cook Jan 12 '15 at 11:34
3

Try these commands Debian, Ubuntu

sudo apt-get install python-dev
sudo apt-get install libpq-dev

For RedHat Enterprise, Fedora, CentOS

sudo yum install python-devel
sudo yum install postgresql-libs

Then Install psycopg2

pip install psycopg2
Yogesh dwivedi Geitpl
  • 4,252
  • 2
  • 20
  • 34
  • 1
    As above; it is already installed. The Django dev server works. Also, running ./manage.py shell then import psycopg2 works. As well as : from psycopg2 import _psycopg – Tim Cook Jan 16 '14 at 11:30
  • are you using python virtualenv for running both way or not ? – Yogesh dwivedi Geitpl Jan 16 '14 at 11:37
  • Yes, the previous site was running under a python 2.7 virtualenv and the new one is installed under a python 3.3 virtualenv. – Tim Cook Jan 16 '14 at 11:47
  • Can you try this one: yum install python33-python-psycopg2 and 'ENGINE': 'django.db.backends.postgresql_psycopg2', may be this work – Yogesh dwivedi Geitpl Jan 16 '14 at 11:54
  • After attempting to break out of dependency hell I am in a circle. Error: Package: python33-python-3.3.2-7.el6.x86_64 (/python33-python-3.3.2-7.el6.x86_64) Requires: python33-python-libs(x86-64) = 3.3.2-7.el6 andError: Package: python33-python-libs-3.3.2-7.el6.x86_64 (/python33-python-libs-3.3.2-7.el6.x86_64) Requires: python33-python(abi) = 3.3 Where python33-python(abi) is provided by python33-python-3.3.2-7.el6.x86_64.rpm – Tim Cook Jan 16 '14 at 13:54
  • Recompiling mod_wsgi with python3.3 and editing the Makefile using flags from python3.3-config --cflags and then with --ldflags; has at least changed the problem to one of a URLs config issue. So I won't call it resolved yet. – Tim Cook Jan 16 '14 at 15:25
0

As has been mentioned, mod_wsgi has not been compiled for python 3. One option is to use Software Collections and/or go with nginx, and "pip install uwsgi" which saves a lot of compiling and running custom packages.

Stickley
  • 4,561
  • 3
  • 30
  • 29