Got "No module named 'dash_html_components'" although it is installed

I’m trying the example code from “basic dash callback”.

However, I got the following error:

❯ python3 test.py    
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import dash_html_components as html
ModuleNotFoundError: No module named 'dash_html_components'

I’m not sure why because I do have dash_html_components installed as shown below, and the python interpreter I’m using in vscode is set as “Python 3.8.12 64-bit (‘base’: conda)” already.

❯ conda list dash    
# packages in environment at /Users/USERNAME/opt/anaconda3:
#
# Name                    Version                   Build  Channel
dash                      2.0.0              pyhd8ed1ab_0    conda-forge
dash-core-components      1.15.0                   pypi_0    pypi
dash-html-components      1.1.2                    pypi_0    pypi
dash-renderer             1.9.0                    pypi_0    pypi
dash-table                4.11.2                   pypi_0    pypi
jupyter-dash              0.4.0              pyhd8ed1ab_0    conda-forge

Have I missed anything important here?

Allow me to reply myself:

This is caused by old versions of dash related packages.

  1. First, update both dash-core-components and dash-html-components to the latest version of 2.0.0:
pip install --upgrade dash-html-components
pip install --upgrade dash-core-components
  1. update the code to call the core and html components:
import dash
# import dash_core_components as dcc    #deprecated
from dash import dcc 
# import dash_html_components as html    #deprecated
from dash import html
from dash.dependencies import Input, Output

I hope the Dash documents can update the contents accordingly.

Glad you figure it out. Note that Input and Output can also be imported from dash directly. More info here.

Very cool, thanks for the link on Dash 2.0 Migration.