1

I had a working mezzanine project configured with apache and mod_wsgi. I tried to added an app to the project and restarted apache and suddenly the project is throwing the error even after undoing the changes. Getting the same error when I'm trying to run python manage.py check:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 284, in execute
    self.validate()
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.7/dist-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 97, in load_app
    app_module = import_module(app_name)
  File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/mezzanine/boot/__init__.py", line 16, in <module>
    from django.apps import apps
ImportError: No module named apps

Path to django: "/usr/local/lib/python2.7/dist-packages/django", and it has folder named "apps" and "init.py" file exists inside the folder.

I then created a whole new mezzanine project and ran python manage.py check, and getting the same error. It means not any mezzanine project is working. I tried updating and reinstalling django and mezzanine but no use. On the other hand, a simple django project is running fine. It seems there is some problem with mezzanine. I went through the other related questions but couldn't get it resolved. Any help would be much appreciated. Thanks in advance.

  • 1
    Error is self explanatory `django.apps` doesn't have `apps` module(it has `config` and `registry`). You should be sure what do you want to import. _May be this_ `from django.apps import AppConfig`. – kapilsdv Aug 03 '16 at 10:24
  • Thanks for the response. This line `from django.apps import apps` pre-exists in many files inside the mezzanine directory. I even tried removing or changing this line, but there are too many files, and changing it creates some other errors. – Utsav Agarwal Aug 03 '16 at 13:32
  • @KapilSachdev `apps` is an attribute in `django/apps/__init__.py`, see [this](https://github.com/django/django/blob/4e64e3bb6e96a50b057bc1144fba3efdee7dfc10/django/apps/__init__.py). @OP What version of Django are you using? – knbk Aug 03 '16 at 14:49

1 Answers1

1

You say you have a folder named apps in your Django installation, but the traceback shows it is executing code that was removed in 1.7, the same version that introduced django.apps. Your installation is most likely corrupt and has files from different versions.

Uninstall Django from your Python installation, and completely remove the /usr/local/lib/python2.7/dist-pacakges/django/ folder. Then, reinstall a Django version that is compatible with your version of Mezzanine.

It seems that you've installed Django into your global Python installation. This can easily cause such problems when multiple projects need to use different versions of python packages. It is recommended to use a virtual environment to manage requirements for your projects in an isolated environment and prevent such conflicts.

knbk
  • 52,111
  • 9
  • 124
  • 122
  • Thank You. I uninstalled django and mezzanine, removed all the folders and only installed mezzanine which installs all the requirements including django on its own. And finally it worked. – Utsav Agarwal Aug 03 '16 at 15:50