1

I have a working Django app called django_trial_on_mac that I recently moved to GitHub in order to deploy it to heroku in the future. I cloned the project to my local GitHub folder on my mac but when I ran the app from the new directory I receive the following error:

Traceback (most recent call last):    
  File     "/Users/danieloram/GitHub/Python_projects_for_github/django_trial_on_mac/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/core/management/__init__.py", line 303, in execute
    settings.INSTALLED_APPS
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File     "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/__init__.py", line 124, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File     "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 807, in _gcd_import
    _gcd_import(parent)
  File     "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 824, in _gcd_import
    raise ImportError(_ERR_MSG.format(name))
ImportError: No module named django_trial_on_mac

I have not yet found a solution to this specific case of the error and am hoping someone could explain or point me towards somewhere I can find the answer. thanks!

Danoram
  • 8,132
  • 12
  • 51
  • 71
  • Ah ok that's a start. I'll look into it and get back to you! – Danoram Jul 19 '15 at 11:37
  • Solved! I was missing an __init__.py file in the `django_trial_on_mac` directory of my application! simple non-standard project directory structure problemlike you said :D Idk how it got removed in the first place.. – Danoram Jul 19 '15 at 12:00

2 Answers2

2

The problem turned out to be that I had a non-standard project directory structure. I was missing an __init__.py file in in my 'django_trial_on_mac' directory. As soon as I created an empty __init__.pyfile there, the app ran normally.

__init__.py files tell Django that the directory should be treated as a package and since this file did not exist in the 'django_trial_on_mac' directory, it could not import the module 'django_trial_on_mac'.

Danoram
  • 8,132
  • 12
  • 51
  • 71
0

Hard to answer without more info, but it looks like something is wrong with PYTHONPATH env variable on your Heroku:

  • it does not include your project directory, or
  • you might have a non-standard project directory structure, or
  • the problem might be something as simple as uploading the project with its parent directory, and not only the project directory...
frnhr
  • 12,354
  • 9
  • 63
  • 90