Can someone please explain this error message? AttributeError: module 'dash' has no attribute 'register'

I am trying to convert my (working, functional) app into a multi-page version, following Adam’s video published in December. But I receive this curious error message.

I can find online references to similar messages, but not to this one specifically, and none that seem to offer clues to a solution. I don’t recall making any changes to the templates, and I think I installed the relevant libraries.

Here is the error message again:

AttributeError: module ‘dash’ has no attribute ‘register’.

There are only three pages in my multi-page app to start, and I thought I had them properly “registered” as shown below. Can anyone shed some light on this issue?

Thank you for your feedback.

1. app.py applicable code, or at least I think so:

app = dash.Dash(
    __name__, plugins=[dl.plugins.pages], external_stylesheets=[dbc.themes.SUPERHERO])

2. submit_recipe.py probable applicable code:

dash.register(page(__name__, path='/'))

external_stylesheets=[dbc.themes.SUPERHERO]

app = dash.Dash(external_stylesheets=external_stylesheets)

3. barchart.py probable applicable code:

dash.register_page(__name__)

external_stylesheets = [dbc.themes.SUPERHERO]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

Hi @robertpfaff,

You have a typo in point 2:

dash.register_page(__name__, path='/')
1 Like

Well, that’s what happens when you stop drinking coffee! :smile:

Thanks so much. It is up and running - but for other, yet defined reasons - it is not working as it should. It looks great, but it suddenly does not accept and process recipes, which it does well as a standalone app.

I guess I have my work cut out for me today.

Thanks again and take care,

Robert

1 Like

Have just had the same issue, although no typo. my workaround was to add the code below into each app page’s code to find the register_page function. Not sure why mine didn’t work as planned, as dash and dash-labs are installed, perhaps I have a PATH issue but not sure

from dash_labs.plugins.pages import register_page

register_page(__name__, path='/')
1 Like

hi @brendon

You don’t have a PATH issue or a typo. dash.register_page was renamed to dash_labs.plugins.register_page in dash-labs version 1.1.0.

There will be an announcement coming soon, but the pages feature is now available in dash 2.5. :confetti_ball:
It was necessary to change the name of register_page because there is a conflict if you use dash-labs version < 1.1.0 and dash >= 2.5.0.

1 Like

I have a simulat issue with my multi page app

dash version: 2.0.0
dash_bootstrap_components version: 1.1.0

Error on my 32 bit Windows:

Traceback (most recent call last):
File “C:\MuliPageAppTest\App\appTest.py”, line 27, in
app = dash.Dash(
File “C:\Users\dash_server\AppData\Local\Programs\Python\Python39-32\lib\site-packages\dash\dash.py”, line 423, in init
plugin.plug(self)
File “C:\Users\dash_server\AppData\Local\Programs\Python\Python39-32\lib\site-packages\dash_labs\plugins\pages.py”, line 327, in plug
_import_layouts_from_pages(pages_folder)
File “C:\Users\dash_server\AppData\Local\Programs\Python\Python39-32\lib\site-packages\dash_labs\plugins\pages.py”, line 301, in import_layouts_from_pages
page_module = importlib.import_module(f"pages.{page_filename}")
File "C:\Users\dash_server\AppData\Local\Programs\Python\Python39-32\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1030, in _gcd_import
File “”, line 1007, in _find_and_load
File “”, line 986, in _find_and_load_unlocked
File “”, line 680, in _load_unlocked
File “”, line 850, in exec_module
File “”, line 228, in _call_with_frames_removed
File “C:\MuliPageAppTest\App\pages\AkustikTest.py”, line 2, in
dash.register_page(name)
AttributeError: module ‘dash’ has no attribute ‘register_page’

Hi @Mae

I recommend upgrading to dash 2.5.1. You can find instructions on how to convert a dash-labs multi-page app to dash and see lots of examples:

I’m having similar issues and can’t figure it out. It looks like I’m following the examples.
I upgraded to dash 2.5.1 yesterday, I don’t use dash_labs.

My file structure is
Index.py
app.py
layout.py (serves the layout to app.py over a function call)
pages/page1.py

I’m getting the following error in the pages/page1.py file
AttributeError: module ‘dash.dash’ has no attribute ‘register_page’
originating from dash.py line 2193 in _import_layouts_from_pages spec.loader.exec_module(page_module)

app.py:
from dash import Dash, html, dcc, callback, Input, Output
import dash
print(f’App started: {dt.now()}')

app = dash.Dash(name, #error with dash.Dash() or just Dash()
use_pages=True,
suppress_callback_exceptions=True,
external_stylesheets=[dbc.themes.LUX],
meta_tags=[
{“name”: “viewport”, “content”: “width=device-width, initial-scale=1”}
])

page1.py:
from dash import dcc, html, Input, Output, callback_context, dash_table
import dash
dash.register_page(name)

def layout():
Layout stuff
return layout

layout = layout()

Any ideas?

Ok so I may have figured it out, I also figured after spending half a day with no success the moment I posted I’d figure something out.

The problem was something with my other import statements which may have overwrote the initial or changed it somehow. I moved the dash.register_page directly under the import dash and it started working.

Now I’m not able to get the nav bar to show. I grabbed the following from the template and all I see is the color and the title Multi page app demo but nothing else.

nav2 = dbc.NavbarSimple(
dbc.Nav(
[
dbc.NavLink(page[“name”], href=page[“path”])
for page in dash.page_registry.values()
if page.get(“top_nav”)
],
),
brand=“Multi Page App Demo”,
color=“primary”,
dark=True,
className=“mb-2”,
)

Hi @john0305

IIt might help to start with a minimal working example. You can find lots of examples in this library:

You can find the app from the announcement video here: dash-multi-page-app-demos/multi_page_example1 at main · AnnMarieW/dash-multi-page-app-demos · GitHub

True.

I ended up removing the if page.get(‘top_nav’) and it showed up.

I think I can work with this now.

Am I supposed to get the attribute error

module ‘dash.dash’ has no attribute ‘register_page’

in version 2.6.1 as well?

Hi @Aroflote

The dash.dash part of the message looks odd to me. Did you try running any of the minimal examples in my multi-page-app-demos library?

You could also try running this to double check the version of Dash you are running:

import dash
print("Dash Version: ",dash.__version__)

from dash import html

app=dash.Dash(__name__)

dash.register_page("page")

app.layout = html.Div("Hello Dash")

if __name__ == "__main__":
    app.run_server(debug=True)



I no longer get an error. Thank you