Django v4 not compatible with Bokeh

Probably, this issue is closely related to bug #11148 on Bokeh GitHub.
I am struggling with Django v4 and Bokeh 2.4.2
Some help please community

Thank you.

@Vulum #11148 only concerns a specific, narrow, direct integration with Django for the Bokeh server. Is that actually your use case? You need to provide details, because the answer is different:

  • If you are actually asking about the specific Bokeh server integration (that uses channels instead of websockets) then that simply does not support Django 4 at this time, and it may never.

  • If you have standalone content, or want to use standard (websocket) Bokeh server embed, i.e. anything from Embedding Bokeh content — Bokeh 2.4.2 Documentation then Django is irrelevant and you have some other issue. In order to help diagnose we would need code/details.

@Bryan, my issue is as shown below:

File "/home/laravel/Documents/djangoWagtailProjects/crime_alert_app/infographics/views.py", line 55, in <module>
    import holoviews as hv
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/holoviews/__init__.py", line 12, in <module>
    from .annotators import annotate                         # noqa (API import)
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/holoviews/annotators.py", line 10, in <module>
    from panel.pane import PaneBase
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/__init__.py", line 47, in <module>
    from . import layout # noqa
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/layout/__init__.py", line 1, in <module>
    from .accordion import Accordion # noqa
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/layout/accordion.py", line 5, in <module>
    from .base import NamedListPanel
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/layout/base.py", line 13, in <module>
    from ..reactive import Reactive
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/reactive.py", line 33, in <module>
    from .viewable import Layoutable, Renderable, Viewable
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/viewable.py", line 26, in <module>
    from .io import serve
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/io/__init__.py", line 25, in <module>
    from . import django # noqa
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/panel/io/django.py", line 4, in <module>
    from bokeh.server.django.consumers import DocConsumer, AutoloadJsConsumer
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/bokeh/server/django/__init__.py", line 5, in <module>
    from .apps import DjangoBokehConfig
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/bokeh/server/django/apps.py", line 29, in <module>
    from .routing import Routing, RoutingConfiguration
  File "/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/bokeh/server/django/routing.py", line 27, in <module>
    from django.conf.urls import url
ImportError: cannot import name 'url' from 'django.conf.urls' (/home/laravel/anaconda3/envs/crime_alert_app/lib/python3.9/site-packages/django/conf/urls/__init__.py)

@Vulum I have two comments:

  • That stack trace indicates that this is indeed about the issue #11148. There is no solution for using Django 4 with bokeh.server.django at this time. And (personal opinion) I very much doubt there will be in the future either, unless some organization decides that they want to fund new development for it.

  • The actual error originates from usage in Panel. Panel is a separate project maintained by a different team of people. It’s possible they have their own updates on their end to handle Django 4 without using bokeh.server.django, but this is not the right place to ask that. Questions about Panel should be directed at the HoloViz Discourse:

    https://discourse.holoviz.org

@Bryan, thank you so much for confirming that, much appreciated, spares me time on trying to figure out the issue. I guess, its time to check out some other plotting libraries.

Much appreciated.

I guess? I do want to be completely clear, at least for any one who might find this later: There are lots of ways to use Bokeh with Django 4, or any general web server, just that don’t use the one experimental bokeh.server.django API under question.

All of the standard embedding APIs at Embedding Bokeh content — Bokeh 2.4.2 Documentation will work with any version of Django.

Duly noted, much appreciated :+1:

In light of this issue, I commented out the following imports in my django view:

#import holoviews as hv
#from holoviews import opts, dim
#from holoviews.streams import Pipe, Buffer
#from holoviews.plotting.bokeh.styles import (line_properties, fill_properties, text_properties)
#from holoviews.operation.timeseries import rolling, rolling_outlier_std

#hv.extension('bokeh')
# hv.extension('matplotlib')
#import panel as pn

And my application was running again. With those commented out lines, I was optimistic that I will still be able to render bokeh graphs in the the django views, however, I go the below error:

"title":"Bokeh Application","version":"2.4.2"}}\';\n                const render_items = [{"docid":"d9454a91-45f6-4ab5-a345-0a7f6eb5eeee","root_ids":["1002"],"roots":{"1002":"b1d62f4f-9ebf-4e01-b596-13291df92936"}}];\n                root.Bokeh.embed.embed_items(docs_json, render_items);\n              \n                }\n                if (root.Bokeh !== undefined) {\n                  embed_document(root);\n                } else {\n                  let attempts = 0;\n                  const timer = setInterval(function(root) {\n                    if (root.Bokeh !== undefined) {\n                      clearInterval(timer);\n                      embed_document(root);\n                    } else {\n                      attempts++;\n                      if (attempts > 100) {\n                        clearInterval(timer);\n                        console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");\n                      }\n                    }\n                  }, 10, root)\n                }\n              })(window);\n            });\n          };\n          if (document.readyState != "loading") fn();\n          else document.addEventListener("DOMContentLoaded", fn);\n        })();\n</script>', 'div': '\n<div class="bk-root" id="b1d62f4f-9ebf-4e01-b596-13291df92936" data-root-id="1002"></div>', 'name_of_prov': 'Chimbu (Simbu)'}}}}

Is this the same error pertaining to the original issue of this blog?

I fixed the error with:

<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.0.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.0.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.0.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.0.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.0.min.js"
        crossorigin="anonymous"></script>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.