Problems with Panel and Django

Hello everyone.

I’m having serious trouble integrating Panel with Django. I have tried using the official guide (https://panel.holoviz.org/user_guide/Django_Apps.html), and also with the examples in GitHub (https://github.com/holoviz/panel/tree/master/examples/apps), but I always have the same problem:

    Exception inside application: __init__() takes 1 positional argument but 2 were given
Traceback (most recent call last):
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/sessions.py", line 254, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/auth.py", line 181, in __call__
    return await super().__call__(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/routing.py", line 150, in __call__
    return await application(
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/asgiref/compatibility.py", line 33, in new_application
    instance = application(scope)
TypeError: __init__() takes 1 positional argument but 2 were given
HTTP GET /sliders 500 [0.33, 127.0.0.1:58367]
Exception inside application: __init__() takes 1 positional argument but 2 were given
Traceback (most recent call last):
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/sessions.py", line 254, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/auth.py", line 181, in __call__
    return await super().__call__(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/channels/routing.py", line 150, in __call__
    return await application(
  File "/Users/jumy/Documents/Development/Python/panel/examples/apps/django_multi_apps/venv/lib/python3.8/site-packages/asgiref/compatibility.py", line 33, in new_application
    instance = application(scope)
TypeError: __init__() takes 1 positional argument but 2 were given
HTTP GET /favicon.ico 500 [0.94, 127.0.0.1:58367]

Any idea of what can be the cause?

Also, pip fails when I try to install requirements.txt:

ERROR: Cannot install -r requirements.txt (line 13), -r requirements.txt (line 8) and param==1.9.2 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested param==1.9.2
    colorcet 2.0.2 depends on param>=1.7.0
    holoviews 1.13.2 depends on param<2.0 and >=1.9.3

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 https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

So I have to install the required packages manually.

Any idea on how I can make this run?

Thanks in advance.

OK, I managed to make run one of the examples, but not before tweaking some of the dependencies.

I had to start with the requirements.txt from the django_multi_apps example. When I tried to install it, I was having the following conflicts:

The conflict is caused by:
    The user requested param==1.9.2
    colorcet 2.0.2 depends on param>=1.7.0
    holoviews 1.13.2 depends on param<2.0 and >=1.9.3

So I removed the version lock to those packages. However, it was still having some other conflicts:

The conflict is caused by:
    The user requested bokeh==1.4.0
    hvplot 0.5.2 depends on bokeh>=1.0.0
    panel 0.9.3 depends on bokeh>=2.0.0

I sorted that by removing the version lock for bokeh.

At the end, my requirements.txt ended like this:

asgiref==3.2.3
attrs==19.3.0
autobahn==19.11.1
Automat==0.8.0
bokeh
cffi==1.13.2
channels==2.4.0
colorcet
constantly==15.1.0
cryptography==3.2
daphne==2.4.1
Django==3.0.7
holoviews
hvplot==0.5.2
hyperlink==19.0.0
idna==2.8
incremental==17.5.0
Jinja2==2.10.3
Markdown==3.1.1
MarkupSafe==1.1.1
numpy==1.18.0
packaging==20.0
pandas==0.25.3
panel==0.9.3
param
Pillow==7.1.0
pyasn1==0.4.8
pyasn1-modules==0.2.7
pycparser==2.19
pyct==0.4.6
PyHamcrest==1.9.0
pyOpenSSL==19.1.0
pyparsing==2.4.6
python-dateutil==2.8.1
pytz==2019.3
pyviz-comms==0.7.4
PyYAML==5.2
service-identity==18.1.0
six==1.13.0
sqlparse==0.3.0
tornado==6.0.3
Twisted==20.3.0
txaio==18.8.1
zope.interface==4.7.1

That allowed the example to work.

There are a few things that I still have to tweak, but this is at least a good start :slight_smile:

I hope this can help to anyone else trying to give a go to Panel in Django.

Hi @realjumy

Welcome to the community and thanks a lot for sharing your problem and solution. Happy you figured it out.

1 Like