deploy app django digitalocean

Hello I have a small problem when I install my packages, I receive this error message

ERROR: Cannot install channels-redis==2.4.2 and channels==3.0.5 because these package versions have conflicting dependencies.

The conflict is caused by:
The user requested channels==3.0.5
channels-redis 2.4.2 depends on channels~=2.2

To fix this you could try to:

  1. loosen the range of package versions you’ve specified
  2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit Dependency Resolution - pip documentation v24.0.dev0

,yet they are the same version of package that I use locally, so when I test this command

gunicorn --bind 0.0.0.0:8000 OrderLine1.asgi

I receive this error

  File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
    mod = importlib.import_module(module)
  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 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/wahab/apporder/OrderLine1/asgi.py", line 14, in <module>
    from channels.routing import ProtocolTypeRouter, URLRouter
ModuleNotFoundError: No module named 'channels'
[2022-11-12 12:35:25 +0000] [28362] [INFO] Worker exiting (pid: 28362)
[2022-11-12 12:35:25 +0000] [28361] [INFO] Shutting down: Master
[2022-11-12 12:35:25 +0000] [28361] [INFO] Reason: Worker failed to boot.

So what do you think the resolution for this may be?

I have encountered the same problem locally, but when I install a previous version it automatically changes me to another version

So what do you think the resolution for this would be?

Use the requirement.txt?

If that’s it, I’ve already tried but it doesn’t work

Looking at the key parts of this:

If you want to use channels version 3.0.5, then you need to install a version of channels-redis compatible with it.

Is there any reason why you’re specifying channels-redis 2.4.2?

because apparently channels redis doesn’t work well with my current version of channels;
but now I don’t have any error but, when I do this command

gunicorn --bind 0.0.0.0:8000 OrderLine1.asgi

, I still have this error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
    mod = importlib.import_module(module)
  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 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/wahab/apporder/OrderLine1/asgi.py", line 14, in <module>
    from channels.routing import ProtocolTypeRouter, URLRouter
ModuleNotFoundError: No module named 'channels'
[2022-11-12 17:16:46 +0000] [32525] [INFO] Worker exiting (pid: 32525)
[2022-11-12 17:16:47 +0000] [32524] [INFO] Shutting down: Master
[2022-11-12 17:16:47 +0000] [32524] [INFO] Reason: Worker failed to boot.

yet here is my request.txt

apporder$ cat requirements.txt
channels==3.0.5
channels-redis==2.4.2
Django==3.1
django-htmx==1.12.2
djangochannelsrestframework==1.0.0
djangorestframework==3.13.1
oauthlib==3.2.0
Pillow==9.2.0
redis==4.3.4
requests==2.28.1

Yes, this is what you need to fix. See my previous reply.

Also, what is the output of a pip list?

Package                     Version
--------------------------- ---------
asgiref                     3.5.2
async-timeout               4.0.2
certifi                     2022.9.24
channels                    4.0.0
channels-redis              4.0.0
charset-normalizer          2.1.1
Deprecated                  1.2.13
Django                      3.2
django-cors-headers         3.13.0
django-extensions           3.2.1
django-htmx                 1.13.0
djangochannelsrestframework 1.1.0
djangorestframework         3.14.0
gunicorn                    20.1.0
idna                        3.4
install                     1.3.5
msgpack                     1.0.4
oauthlib                    3.2.2
packaging                   21.3
Pillow                      9.3.0
pip                         22.3
psycopg2                    2.9.5
pyparsing                   3.0.9
pytz                        2022.6
redis                       4.3.4
requests                    2.28.1
setuptools                  65.5.0
sqlparse                    0.4.3
urllib3                     1.26.12
wheel                       0.37.1
wrapt                       1.14.1

[notice] A new release of pip available: 22.3 -> 22.3.1
[notice] To update, run: pip install --upgrade pip

Is this pip list for your global environment or for your virtual environment?

If for a virtual environment, are you activating that environment before running gunicorn?

yes look

(env) wahab@django411onubuntu:~/apporder$ pip list

(env) wahab@django411onubuntu:~/apporder$ gunicorn --bind 0.0.0.0:8000 OrderLine1.asgi

[2022-11-12 17:35:56 +0000] [32693] [INFO] Starting gunicorn 20.1.0
[2022-11-12 17:35:56 +0000] [32693] [INFO] Listening at: http://0.0.0.0:8000 (32693)
[2022-11-12 17:35:56 +0000] [32693] [INFO] Using worker: sync
[2022-11-12 17:35:56 +0000] [32694] [INFO] Booting worker with pid: 32694
[2022-11-12 17:35:57 +0000] [32694] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
    mod = importlib.import_module(module)
  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 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/wahab/apporder/OrderLine1/asgi.py", line 14, in <module>
    from channels.routing import ProtocolTypeRouter, URLRouter
ModuleNotFoundError: No module named 'channels'
[2022-11-12 17:35:57 +0000] [32694] [INFO] Worker exiting (pid: 32694)
[2022-11-12 17:35:57 +0000] [32693] [INFO] Shutting down: Master
[2022-11-12 17:35:57 +0000] [32693] [INFO] Reason: Worker failed to boot.

And you have both daphne and channels in INSTALLED_APPS in your settings.py file?

(I see where you’ve upgraded to Channels 4 - that has slightly different installation requirements - see Installation — Channels 4.0.0 documentation)

Ack, silly me, I missed the obvious answer.

gunicorn is a wsgi server, not an asgi server.

See Deploying — Channels 4.0.0 documentation

You need to either use daphne, or something like uvicorn to run your application.

so I have to uninstall gunicorn==20.1.0 and install unicorn instead?

You can uninstall gunicorn, but that’s not strictly necessary. (Having packages installed that you don’t use doesn’t cause problems.)

As for the rest, it’s all covered in the referenced docs.

I installed gunicorn with pip but also just after creating env, so I have to delete it too in env?

look here

wahab@django411:~/apporder/env$ cd bin/
wahab@django411:~/apporder/env/bin$ ls
__pycache__  activate.csh   activate.nu   activate_this.py  django-admin     gunicorn    pip       pip3     python   python3.10  wheel       wheel3
activate     activate.fish  activate.ps1  deactivate.nu     django-admin.py  normalizer  pip-3.10  pip3.10  python3  sqlformat   wheel-3.10  wheel3.10

Should I delete it in the env?

I answered this in my previous response.

I read the Daphne documentaion Deploying — Channels 4.0.0 documentation, I don’t have to use uvicorn if I use Daphne, right?