Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'pages.' #113

Closed
charmeem opened this issue Jun 13, 2022 · 24 comments
Closed

ModuleNotFoundError: No module named 'pages.' #113

charmeem opened this issue Jun 13, 2022 · 24 comments

Comments

@charmeem
Copy link

charmeem commented Jun 13, 2022

When trying to run the demo code of Chapter08-MultiPageDashApp I am getting this error.
This error however doesn't generates if I include only histogram.py file in /pages folder.
As I add other files like bar_charts.py this error appears.

Detail print out:

(base) c:\my_drive\python\dashboards\plotlydash\flaskdash1>python app.py
Traceback (most recent call last):
  File "app.py", line 6, in <module>
    app = dash.Dash(
  File "C:\Users\hp\anaconda3\lib\site-packages\dash\dash.py", line 420, in __init__
    plugin.plug(self)
  File "C:\Users\hp\anaconda3\lib\site-packages\dash_labs\plugins\pages.py", line 327, in plug
    _import_layouts_from_pages(pages_folder)
  File "C:\Users\hp\anaconda3\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\hp\anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pages.'
@charmeem
Copy link
Author

This issue is resolved after upgrading dash to 2.5 and following suggestions in earlier issue#112

@charmeem charmeem reopened this Jun 13, 2022
@charmeem
Copy link
Author

charmeem commented Jun 13, 2022

However Now I am getting ' Duplicate callback Outputs' for every callback although there is no duplicate Output exits.

Error:

In the callback for output(s):
  histograms-graph.figure
Output 0 (histograms-graph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.

histogram.py file:

from dash import Dash, dcc, html, Input, Output, callback
from dash import register_page
import plotly.express as px
import numpy as np

register_page(__name__)

np.random.seed(2020)

layout = html.Div(
    [
        dcc.Graph(id="istograms-graph"),
        html.P("Mean:"),
        dcc.Slider(
            id="histograms-mean", min=-3, max=3, value=0, marks={-3: "-3", 3: "3"}
        ),
        html.P("Standard Deviation:"),
        dcc.Slider(id="histograms-std", min=1, max=3, value=1, marks={1: "1", 3: "3"}),
    ]
)


@callback(
    Output("histograms-graph", "figure"),
    Input("histograms-mean", "value"),
    Input("histograms-std", "value"),
)
def display_color(mean, std):
    
    data = np.random.normal(mean, std, size=500)
    fig = px.histogram(data, nbins=30, range_x=[-10, 10])
    return fig

@charmeem
Copy link
Author

charmeem commented Jun 13, 2022

import dash
import dash_bootstrap_components as dbc


app = dash.Dash(
    __name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP]
)

navbar = dbc.NavbarSimple(
    dbc.DropdownMenu(
        [
            dbc.DropdownMenuItem(page["name"], href=page["path"])
            for page in dash.page_registry.values()
            if page["module"] != "pages.not_found_404"
        ],
        nav=True,
        label="More Pages",
    ),
    brand="Multi Page App Plugin Demo",
    color="primary",
    dark=True,
    className="mb-2",
)

app.layout = dbc.Container(
    [navbar, dash.page_container],
    fluid=True,
)

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

@AnnMarieW
Copy link
Collaborator

HI @charmeem
Are you on Windows? If so, this is a bug and will be fixed in 2.5.1. The new release with the patch is coming soon.

@charmeem
Copy link
Author

Yes I am using Windows.
Will wait for the new release, thanks.

@AnnMarieW
Copy link
Collaborator

Hi @charmeem 5.1 was just released 🎊

Could you try running these multi-page sample apps and let me know how it goes?: https://github.com/AnnMarieW/dash-multi-page-app-demos

@charmeem
Copy link
Author

Hello,
I have just tried after upgrading to 2.5.1 , still seeing the same errors however with one improvement.
I can see the pages in the navigation bar which was not the case before.

Secondly when I add a page 'heatmaps.py' in the /pages folder following error appears:

Exception
Exception: modules ['pages..ipynb_checkpoints.heatmaps-checkpoint', 'pages.heatmaps'] have duplicate paths

Traceback (most recent call last)
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\hp\anaconda3\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1945, in full_dispatch_request
self.try_trigger_before_first_request_functions()
File "C:\Users\hp\anaconda3\Lib\site-packages\flask\app.py", line 1993, in try_trigger_before_first_request_functions
func()
File "C:\Users\hp\anaconda3\Lib\site-packages\dash\dash.py", line 2268, in router
_validate.check_for_duplicate_pathnames(_pages.PAGE_REGISTRY)
File "C:\Users\hp\anaconda3\Lib\site-packages\dash_validate.py", line 435, in check_for_duplicate_pathnames
raise Exception(f"modules {modules} have duplicate paths")

@charmeem
Copy link
Author

Capture

@AnnMarieW
Copy link
Collaborator

🤔 So, you see these errors when you run one of the apps from the github repo I shared the link to previously?

@AnnMarieW
Copy link
Collaborator

can you share the code you are running? It looks like there might be conflicts between "Histogram" and "Histogram-checkpoint" for example

@charmeem
Copy link
Author

wait

@charmeem
Copy link
Author

Yes I am running codes in multi_page_example_1

@charmeem
Copy link
Author

app.py

import dash
import dash_bootstrap_components as dbc


app = dash.Dash(
    __name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP]
)

navbar = dbc.NavbarSimple(
    dbc.DropdownMenu(
        [
            dbc.DropdownMenuItem(page["name"], href=page["path"])
            for page in dash.page_registry.values()
            if page["module"] != "pages.not_found_404"
        ],
        nav=True,
        label="More Pages",
    ),
    brand="Multi Page App Plugin Demo",
    color="primary",
    dark=True,
    className="mb-2",
)

app.layout = dbc.Container(
    [navbar, dash.page_container],
    fluid=True,
)

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

@AnnMarieW
Copy link
Collaborator

AnnMarieW commented Jun 13, 2022

This looks odd:

Exception: modules ['pages..ipynb_checkpoints.heatmaps-checkpoint', 'pages.heatmaps'] have duplicate paths

Do you know where 'pages..ipynb_checkpoints.heatmaps-checkpoint might be coming from?

@charmeem
Copy link
Author

histogram.py

from dash import Dash, dcc, html, Input, Output, callback
from dash import register_page
import plotly.express as px
import numpy as np

register_page(__name__)

np.random.seed(2020)

layout = html.Div(
    [
        html.P("Mean:"),
        dcc.Slider(
            id="histograms-mean", min=-3, max=3, value=0, marks={-3: "-3", 3: "3"}
        ),
        html.P("Standard Deviation:"),
        dcc.Slider(id="histograms-std", min=1, max=3, value=1, marks={1: "1", 3: "3"}),
        dcc.Graph(id="histograms-graph"),
    ]
)


@callback(
    Output("histograms-graph", "figure"),
    Input("histograms-mean", "value"),
    Input("histograms-std", "value")    
)
def display_color(mean, std):
    
    data = np.random.normal(mean, std, size=500)
    fig = px.histogram(data, nbins=30, range_x=[-10, 10])
    return fig

@charmeem
Copy link
Author

It is now working.
ipynb_checkpoints was the directory automaticaly created by Jupyter note book. After removing that the code is wording fine.

Let me test with heatmaps.py page as well.

@charmeem
Copy link
Author

All working now, Thanks for your hints.

@AnnMarieW
Copy link
Collaborator

oh, great - thanks! Now we'll know what to do for the next person who might have a similar issue 👍

@charmeem
Copy link
Author

Can I close the case?

@AnnMarieW
Copy link
Collaborator

yes, please

@charmeem
Copy link
Author

OK, appreciate the work you are doing designing this wonderful product, keep it up !

@Damistar05
Copy link

Hi. Please am trying to deploy my link to render. But am getting errors: dash.exceptions.NoLayoutException: The layout was None at the time that run_server was called. Make sure to set the layout attribute of your application before running the server

@alexcjohnson
Copy link
Collaborator

Hi @Damistar05 - If you can post your code and your question on https://community.plotly.com/ there are lots of folks who will be happy to help!

@AnnMarieW
Copy link
Collaborator

Hi @Damistar05 - please don't use this version - this was a prototype used to develop the Dash Pages feature and is no longer being maintained. This feature is now part of Dash :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants