0

I am trying to add web sockets to my Django application. From my existing project, I starting following the Chat app found in the Daphne documentation. I installed Daphne and Channels, add daphne to the top of Installed Apps and reconfigure asgi.py exactly like the instructions. When I run the server, I get the following error.

❯ python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/core/management/__init__.py", line 394, in execute
    autoreload.check_errors(django.setup)()
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/home/ben/Projects/tabshare/tabshare-backend/src/tabshare_backend/venvdaphne/lib/python3.10/site-packages/django/apps/config.py", line 193, in create
    import_module(entry)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'daphnedjango'

If I create a blank Django project and follow the exact steps everything works correctly.

I cannot for the life of me even begin to track down where this error is coming from.

So far I have tried the following...

  • comment out all custom configuration in settings.py to try and bring the configuration file as close as possible back to the default.
  • Systematically uninstall third party apps with the hope that one of them is causing the error.
  • Comment out all routes in urls.py. I admit, this was a panic move. I increasingly do not understand what is going on.
  • Ask ChatGPT. It told me to install daphnedjango. The AI is getting sassy. FYI daphnedjango is not module that I can/need to install over pip.

I know this is a bit of a vague question, but outside of posting my entire project, I'm not even sure what would be helpful to share. I'm happy to append anything that would be helpful in tracking down the solution.

bdempe
  • 308
  • 2
  • 9
  • 4
    I'm going to make a wild guess that somewhere in your app, you have a list of modules (as strings) that contains `'daphne'` and `'django'` next to each other, _but you forgot to put a comma in between them_, and so Python combined them into one single string. – John Gordon Jun 07 '23 at 00:33
  • Genius level. Thank you so much. What a stupid stupid error. Curiously, the the section of the installed apps list that was problematic was ["daphne" "django.contrib.admin"....] which traceback read as "daphnedjango". If you upgrade your comment to an answer I can give you the reps for answering. – bdempe Jun 07 '23 at 02:18

0 Answers0