Search code examples
pythondjangoherokuattributeerror

Django - Heroku push succeeds but getting AttributeError (module has no attribute)


I pushed my web app to Heroku and it built / deployed fine, but I get this error when I access it:

AttributeError at /
module 'wakemeup.models' has no attribute 'environment'
Exception Location: /app/lib/UsefulFunctions/googleUtils.py in <module>, line 16
Python Executable:  /app/.heroku/python/bin/python
Python Version: 3.6.10
Python Path:    
['/app/.heroku/python/bin',
 '/app',
 '/app/.heroku/python/lib/python36.zip',
 '/app/.heroku/python/lib/python3.6',
 '/app/.heroku/python/lib/python3.6/lib-dynload',
 '/app/.heroku/python/lib/python3.6/site-packages']

It works fine locally, so my first thought was the PYTHONPATH, but it seems to be similar locally:

Python Path:    
['C:\\Users\\ravioli\\projects\\dcp',
 'C:\\Program Files (x86)\\Python38-32\\python38.zip',
 'C:\\Program Files (x86)\\Python38-32\\DLLs',
 'C:\\Program Files (x86)\\Python38-32\\lib',
 'C:\\Program Files (x86)\\Python38-32',
 'C:\\Program Files (x86)\\Python38-32\\lib\\site-packages']

Directory structure (simplified)

enter image description here

googleUtils.py (simplified)

import os
import sys
import io
import copy
from urllib.error import HTTPError

# Import - Google
from google.oauth2 import service_account
...

# Import - Application
from lib.UsefulFunctions.dataUtils import get_setting
import wakemeup.models.environment as env

class GoogleDriveManager():
 ...

I originally had the import wakemeup.models.environment as env line as from ... import but that was giving me a circular dependency error, so I changed it and it works fine locally. Not sure if that has to do with it.

How can I fix this so it works on Heroku?


Solution

  • I changed the import statement and it works now:

    from wakemeup import models
    # import wakemeup.models.environment as env # original
    

    Maybe there was another module named environment that Heroku uses, not sure.