sivabalan19
sivabalan19

Reputation: 89

ImportError: No module named asgi

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.

Upvotes: 3

Views: 14286

Answers (5)

user183240
user183240

Reputation:

More than likely the asgi.py file you created is in the wrong directory.

It should be in the same directory as your settings.py and wsgi.py files.

Upvotes: 1

Jamie Counsell
Jamie Counsell

Reputation: 8143

I ran into this issue when I was debugging a server and running the daphne command from the command line. I was running a command like:

/home/myuser/.virtualenvs/myapp/bin/python /home/myuser/.virtualenvs/myapp/bin/daphne -b 0.0.0.0 -p 8080  core.asgi:channel_layer

And it was still failing. Turns out I had to cd into the same directory as manage.py to get it running. If you're using something like systemctl, you can just set the working directory to the same location.

Upvotes: 1

Sylvia Onwukwe
Sylvia Onwukwe

Reputation: 153

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.

Upvotes: 3

IVI
IVI

Reputation: 2116

Make sure you've installed it and double check you've activated the virtualenv.

pip install -U asgi_redis

Upvotes: 2

TinyX
TinyX

Reputation: 21

Use

pip show channels

To see the version of your package.

channels.asgi was not there until version 0.9:

https://github.com/andrewgodwin/channels/tree/0.8/channels https://github.com/andrewgodwin/channels/tree/0.9/channels

Upvotes: 1

Related Questions