dash_bootstrap_components已成功安装,但未识别

时间:2020-02-01 23:19:20

标签: python twitter-bootstrap hyphen

我的仪表板工作正常。我已经安装dash_bootstrap_components来给仪表板赋予样式。

我写了'pip install dash-bootstrap-components',并且安装正确。

但是当我运行应用程序时,出现此错误:

将dash_bootstrap_components导入为dbc ModuleNotFoundError:没有名为“ dash_bootstrap_components”的模块

我有: 破折号1.8.0 dash-bootstrap-components-0.8.2

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,我尝试按照其网站上的说明进行安装:https://dash-bootstrap-components.opensource.faculty.ai/docs/quickstart/

在终端命令行中,输入以下内容:

pip install dash-bootstrap-components

我遇到以下错误:

由于环境错误而无法安装软件包:[Errno 13]权限被拒绝:考虑使用--user选项或检查权限。

要解决此问题,您可以执行以下操作(第一个对我有用):

1)将软件包安装到用户文件夹:

python -m pip install --user dash-bootstrap-components

2)设置虚拟环境以安装软件包:

python3 -m venv env
source ./env/bin/activate 
python -m pip install dash-bootstrap-components

3)使用sudo安装到系统文件夹(不推荐)

sudo python -m pip install dash-bootstrap-components

完成该操作后,您可以使用以下代码创建文件并运行服务器以查看其是否有效

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container(
    dbc.Alert("Hello Bootstrap!", color="success"),
    className="p-5",
)

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