Error deploying Django with ImageKit using Apache "cannot import name conf"
Question: I'm trying to deploy my Django site with Apache but I'm running into issues
with the ImageKit library. Here's the error from /var/log/apache2/error.log:

    
    
    No handlers could be found for logger "django.request"
    [1.2.3.4] mod_wsgi (pid=17276): Exception occurred processing WSGI script '/var/www/mysite.com/portfoliosite/portfoliosite/wsgi.py'.
    [1.2.3.4] Traceback (most recent call last):
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
    [1.2.3.4]     response = self.get_response(request)
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/base.py", line 218, in get_respo$
    [1.2.3.4]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/handlers/base.py", line 264, in handle_un$
    [1.2.3.4]     if resolver.urlconf_module is None:
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 395, in urlconf_mo$
    [1.2.3.4]     self._urlconf_module = import_module(self.urlconf_name)
    [1.2.3.4]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    [1.2.3.4]     __import__(name)
    [1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfoliosite/urls.py", line 21, in <module>
    [1.2.3.4]     url(r'^', include('portfolio.urls')), # route root through portfolio routes
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 33, in include
    [1.2.3.4]     urlconf_module = import_module(urlconf_module)
    [1.2.3.4]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    [1.2.3.4]     __import__(name)
    [1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/urls.py", line 3, in <module>
    [1.2.3.4]     from . import views
    [1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/views.py", line 9, in <module>
    [1.2.3.4]     from .models import Project
    [1.2.3.4]   File "/var/www/mysite.com/portfoliosite/portfolio/models.py", line 2, in <module>
    [1.2.3.4]     from imagekit.models import ImageSpecField
    [1.2.3.4]   File "/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/imagekit/__init__.py", line 2, in <module>
    [1.2.3.4]     from . import conf
    [1.2.3.4] ImportError: cannot import name conf
    

Does anybody know what might be causing this to happen? Doing "sudo python3
manage.py runserver" works fine, but Apache runs into this library error.
Here's some more relevant info:

wsgi.py:

    
    
    import os
    import sys
    import site
    
    # Add the site-packages of the chosen virtualenv to work with
    site.addsitedir('/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/')
    
    # Add the app's directory to the PYTHONPATH
    sys.path.append('/var/www/mysite.com/portfoliosite')
    sys.path.append('/var/www/mysite.com/portfoliosite/portfoliosite')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'portfoliosite.settings'
    
    # Activate your virtual env
    activate_env=os.path.expanduser('/home/ubuntu/.virtualenvs/portfoliositeenv/bin/activate_this.py')
    exec(open(activate_env).read(), dict(__file__=activate_env))
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

/etc/apache2/apache2.conf (the part I added):

    
    
    WSGIPythonPath /var/www/mysite.com/portfoliosite:/home/ubuntu/.virtualenvs/portfoliositeenv/lib/python3.4/site-packages/
    
    Alias /media/ /var/www/mysite.com/portfoliosite/portfolio/media/
    Alias /static/ /var/www/mysite.com/static/
    
    <Directory /var/www/mysite.com/static>
        Require all granted
    </Directory>
    
    <Directory /var/www/mysite.com/media>
        Require all granted
    </Directory>
    
    WSGIScriptAlias / /var/www/mysite.com/portfoliosite/portfoliosite/wsgi.py
    
    <Directory /var/www/mysite.com/portfoliosite>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
    

This is really frustrating, and any help would be appreciated. Thank you!


Answer: Figured it out! I was mixing Python versions, you can see some paths in the
logs pointing at Python 2.7 while my virtualenv was using Python 3. I created
a new virtual environment and changed all paths to use Python 2.7, and it
seems to be working now.

