ImportError: No module named asgi

sivabalan19 picture sivabalan19 · Mar 28, 2016 · Viewed 9.3k times · Source

Why does :

from channels.asgi import get_channel_layer

results in :

from channels.asgi import get_channel_layer
ImportError: No module named asgi

I am using Django (1.9) and python(3.4). And, while editing in pycharm, i see the IDE is giving me the quick tip for me.

Answer

Sylvia Onwukwe picture Sylvia Onwukwe · May 22, 2019

I was able to fix this; if you are using channels 2, the channel layer is quite different from the older version.

I suggest you to try the following:

  1. Confirm that you have configured your channel layer on settings.py:

    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels_redis.core.RedisChannelLayer",
            "CONFIG": {
                "hosts": [("redis-server-name", 6379)],
            },
        },
    }
    

    Hopefully, you have installed redis if using redis.

  2. Add the channel layer to asgi.py file:

    from channels.layers import get_channel_layer
    
    channel_layer = get_channel_layer()
    

You can see this solution.