Forums

ImportError (bad path setup?)

I'm trying to test whether I can deploy an opensource terminology server for translation projects with WSGI (it works on a local development server) and I think I'm doing something silly! I've set up a virtualenv for the project with Django 1.4.5 and all the module requirements.

The application is in /home/fau/terminator The settings.py is in /home/fau/terminator/project (there are also two folders under this directory terminator and terminator_comments_app)

My WSGI file looks like this:

activate_this = '/home/fau/.virtualenvs/test/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys
#
## assuming your django settings file is at '/home/fau/mysite/settings.py'
path = '/home/fau/terminator'
if path not in sys.path:
    sys.path.append(path)
#
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
#
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

But I get the following error:

2013-07-04 17:33:11,976 :Traceback (most recent call last):
2013-07-04 17:33:11,977 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
2013-07-04 17:33:11,977 :    response = self.get_response(request)
2013-07-04 17:33:11,978 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
2013-07-04 17:33:11,978 :    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2013-07-04 17:33:11,978 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 221, in handle_uncaught_exception
2013-07-04 17:33:11,979 :    return debug.technical_500_response(request, *exc_info)
2013-07-04 17:33:11,979 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 66, in technical_500_response
2013-07-04 17:33:11,980 :    html = reporter.get_traceback_html()
2013-07-04 17:33:11,980 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 287, in get_traceback_html
2013-07-04 17:33:11,981 :    return t.render(c)
2013-07-04 17:33:11,981 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/base.py", line 140, in render
2013-07-04 17:33:11,982 :    return self._render(context)
2013-07-04 17:33:11,982 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
2013-07-04 17:33:11,982 :    return self.nodelist.render(context)
2013-07-04 17:33:11,982 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/base.py", line 823, in render
2013-07-04 17:33:11,983 :    bit = self.render_node(node, context)
2013-07-04 17:33:11,983 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node
2013-07-04 17:33:11,984 :    return node.render(context)
2013-07-04 17:33:11,984 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 84, in render
2013-07-04 17:33:11,985 :    output = self.filter_expression.resolve(context)
2013-07-04 17:33:11,985 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/base.py", line 599, in resolve
2013-07-04 17:33:11,986 :    new_obj = func(obj, *arg_vals)
2013-07-04 17:33:11,986 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/template/defaultfilters.py", line 718, in date
2013-07-04 17:33:11,986 :    return format(value, arg)
2013-07-04 17:33:11,987 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/dateformat.py", line 310, in format
2013-07-04 17:33:11,987 :    return df.format(format_string)
2013-07-04 17:33:11,987 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/dateformat.py", line 33, in format
2013-07-04 17:33:11,988 :    pieces.append(force_unicode(getattr(self, piece)()))
2013-07-04 17:33:11,988 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/dateformat.py", line 214, in r
2013-07-04 17:33:11,989 :    return self.format('D, j M Y H:i:s O')
2013-07-04 17:33:11,989 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/dateformat.py", line 33, in format
2013-07-04 17:33:11,989 :    pieces.append(force_unicode(getattr(self, piece)()))
2013-07-04 17:33:11,990 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/encoding.py", line 71, in force_unicode
2013-07-04 17:33:11,990 :    s = unicode(s)
2013-07-04 17:33:11,990 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/functional.py", line 121, in __unicode_cast
2013-07-04 17:33:11,991 :    return func(*self.__args, **self.__kw)
2013-07-04 17:33:11,991 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 86, in ugettext
2013-07-04 17:33:11,992 :    return _trans.ugettext(message)
2013-07-04 17:33:11,992 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 278, in ugettext
2013-07-04 17:33:11,992 :    return do_translate(message, 'ugettext')
2013-07-04 17:33:11,992 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 268, in do_translate
2013-07-04 17:33:11,993 :    _default = translation(settings.LANGUAGE_CODE)
2013-07-04 17:33:11,993 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 183, in translation
2013-07-04 17:33:11,994 :    default_translation = _fetch(settings.LANGUAGE_CODE)
2013-07-04 17:33:11,994 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 160, in _fetch
2013-07-04 17:33:11,995 :    app = import_module(appname)
2013-07-04 17:33:11,995 :  File "/home/fau/.virtualenvs/test/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-04 17:33:11,995 :    __import__(name)
2013-07-04 17:33:11,996 :ImportError: No module named terminator

Am I putting folders in the wrong place or not setting the path like I'm supposed to? I just can't seem to get it...

Thanks in advance for any help

We've all got to learn somewhere...

I copied the folders terminator and terminator_comments_app to the site-packages directory in my virtualenv and it worked (although I still need to make sure the static folders work).

I still don't understand why the module terminator and terminator_comments_app couldn't be found but I'm chuffed I got this far! Thanks to anyone who takes the time to help out :)

if you want to be able to import terminator you have to make sure the folder that contains terminator is in your sys.path... so, its parent folder, not the terminator folder itself. Does that make sense?