[Django]-Errors running geodjango based apps on heroku

0👍

I’m about 93.2% sure that this is a path problem. One of the major PITAs in web development is that your command line environment may have next to nothing in common with the server’s environment.

I use the following when I need to know exactly what version of which modules are being loaded from what directory. It returns a list of 2-tuples ('name', 'path-to-module'). Call this after your initialization is completed, or just before and/or after you attempt to load your geo module (or other equally interesting places), and dump the results to the screen or a log file.

I don’t know that this will solve your problem, but it may give you some interesting insights.

Note: You can edit (or comment out) the re.sub()s to taste. I just put them in because a big page of absolute path names is hard on the eyes and can mask the fact that something is loading from the system’s copy of something rather than your own copy of it.

modulelist.py

import sys, re, os
import django

def ModuleList():
    ret = []
    dir_project = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    project_name = os.path.basename(dir_project)

    for k,v in sys.modules.items():

        x = str(v)
        if 'built-in' in x:
            ret.append((k, 'built-in'))
            continue

        m = re.search(r"^.*?'(?P<module>.*?)' from '(?P<file>.*?)'.*$", x)
        if m:
            d = m.groupdict()
            f = d['file']
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/site-packages/django/', 'system django >> ', f)
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/site-packages/', 'site-packages >> ', f)
            f = re.sub(r'/usr/.*?/lib/python[.0-9]*/', 'system python >> ', f)
            f = re.sub(dir_project+'.*python/', 'local python >> ', f)
            f = re.sub(dir_project+'.*django/', 'local django >> ', f)
            f = re.sub(dir_project+r'(/\.\./)?', project_name + ' >> ', f)
            ret.append((d['module'], f))
    ret.sort( lambda a,b: cmp(a[0].lower(), b[0].lower()) )
    ret.insert(0, ('Python version', sys.version) )
    ret.insert(0, ('Django version', django.get_version()) )

    return ret
# ModuleList

if __name__ == "__main__":
    for x in ModuleList():
        print "%s\t%s" % (x[0], x[1])

Leave a comment