Django Channels Error - Cannot import BACKEND 'asgi_redis.RedisChannelLayer'

17,138

Solution 1

Just needed to install 'asgi_redis'. I was assuming that it would have gotten installed by default while installing Django-Channels, but it doesn't. 'asgiref' gets installed by default and not 'asgi_redis'. So to solve this issue, one can just run:

> sudo pip install asgi_redis

Solution 2

In regard to Utkarsh's reply itt's been renamed to:

pip install channels-redis

Solution 3

I also faced same problem while working with django-channels, by following the documentation examples https://channels.readthedocs.io/en/latest/tutorial/index.html you just need to install channels-redis as

pip install channels-redis

to resolve this issue.

Solution 4

With asgiref-2.3.2 and maybe more, you need to install channel_redis.

NOT asgi_redis.

pip install channel_redis

Solution 5

Faced the similar issue. Solved it by installing channels_redis:

pip install channels_redis

Also using channel redis in setting too:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
    },
    'ROUTING': 'ws.routing.application',
}
Share:
17,138
Utkarsh Sinha
Author by

Utkarsh Sinha

I am a coder, entrepreneur and science enthusiast. Currently I am building a new age technology consulting business - Betaflux, with a team of highly motivated and skilled developers, and aim to help businesses integrate the right set of technologies to achieve business goals. I also co-founded Clerro, in 2016, to build a dedicated platform for high quality written content on intellectual topics. Our team learnt and massively skilled up both in web-technologies and in business during the 2 years of running Clerro, at one point even interviewing with YCombinator in San Francisco. I also love good food, watching documentaries and dreaming about the future over coffee.

Updated on June 11, 2022

Comments

  • Utkarsh Sinha
    Utkarsh Sinha almost 2 years

    I have installed Django-Channels but while running the daphne-server I am getting this error given below:

    File "/usr/local/lib/python2.7/dist-packages/channels/asgi.py", line 36, in make_backend
    "Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name)
    
    channels.asgi.InvalidChannelLayerError: Cannot import BACKEND 'asgi_redis.RedisChannelLayer' specified for default
    

    My settings.py is:

    CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_redis.RedisChannelLayer",
        "CONFIG": {
            "hosts": [os.environ.get('REDIS_URL', 'redis://X.X.X.X:6379')],
        },
        "ROUTING": "MyProject.routing.channel_routing",
    },
    }
    

    Need help in resolving this error.

  • user42488
    user42488 about 6 years
    I found this to be also true for "Cannot import BACKEND 'channels_redis.core.RedisChannelLayer'": pip install channels_redis. Thank you.
  • jlSta
    jlSta over 5 years
    With asgiref-2.3.2 i need to install channel_redis. NOT asgi_redis
  • Mike Spike
    Mike Spike over 5 years
    @jlSta, great, this solved one of the issues with new channels 2.x, wish it was written in the docs (and, it's channels_redis)
  • jlSta
    jlSta over 5 years
    I add this as a solution, so
  • rprasad
    rprasad over 5 years
    Yes! Use this for channels. I am using channels 2.1.5. e.g. pip install channels==2.1.5 (This version also installs asgiref==2.3.2)
  • rprasad
    rprasad over 5 years
    See comment from jlSta above, e.g. pip install channel_redis
  • Utkarsh Sinha
    Utkarsh Sinha over 5 years
    Thanks for pointing it out @drulang. For anyone trying to install Django Channels 2, the documentation describes the changes that have taken place here - channels.readthedocs.io/en/latest/…
  • fanny
    fanny over 4 years
    I think it should be channels_redis