在jupyter实验室中不进行情节快递

时间:2019-08-11 14:36:14

标签: python plotly jupyter-lab plotly-express

以下代码在Jupyter实验室中不呈现:

%matplotlib widget
import plotly.express as px  
import numpy as np 
import pandas as pd

df = pd.DataFrame(np.random.randint(0,100,size=(5, 4)), columns=list('ABCD'))
px.bar(df, x='A', y='B')

enter image description here 我试图安装这里提到的所有依赖项和扩展 https://plot.ly/python/getting-started/#jupyterlab-support-python-35

而且这里的步骤 https://github.com/matplotlib/jupyter-matplotlib

什么都没做

这是我的设置:

jupyter lab --version
1.0.2

python --version
Python 3.6.1 :: Continuum Analytics, Inc.

conda list jupyterlab
# packages in environment at C:\Users\***\Anaconda3:
#
# Name                    Version                   Build  Channel
jupyterlab                1.0.2            py36hf63ae98_0
jupyterlab_launcher       0.13.1                   py36_0
jupyterlab_server         1.0.0                      py_0

conda list nodejs
# packages in environment at C:\Users\***\Anaconda3:
#
# Name                    Version                   Build  Channel
nodejs                    0.1.1                    pypi_0    pypi

conda list plotly
# packages in environment at C:\Users\***\Anaconda3:
#
# Name                    Version                   Build  Channel
plotly                    4.1.0                    pypi_0    pypi
plotly-express            0.4.1                    pypi_0    pypi

编辑:

jupyter-labextension list
JupyterLab v1.0.2
Known labextensions:
   app dir: C:\Users\***\Anaconda3\share\jupyter\lab
        @jupyter-widgets/jupyterlab-manager v1.0.2 enabled  ok
        @jupyterlab/git v0.8.0 enabled  ok
        @jupyterlab/plotly-extension v1.0.0 enabled  ok
        jupyter-matplotlib v0.4.2 enabled  ok
        jupyterlab-chart-editor v1.2.0 enabled  ok
        jupyterlab-plotly v1.1.0 enabled  ok
        plotlywidget v1.1.0 enabled  ok

4 个答案:

答案 0 :(得分:1)

可能是以前安装的残余物或尝试进行安装导致问题。我建议从全新安装开始或卸载所有Plotly模块(从pip和conda!)以及与plotly相关的jlab扩展,然后按照此处的说明进行操作:https://plot.ly/python/getting-started/

卸载模块只需

conda uninstall plotly
pip uninstall plotly

然后根据上面链接的说明重新安装其中一个,但不能同时安装。

卸载JupyterLab扩展是通过

jupyter labextension uninstall @jupyterlab/plotly-extension
jupyter labextension uninstall jupyterlab-plotly 
jupyter labextension uninstall plotlywidget

答案 1 :(得分:1)

按照官方的plotly.py repo https://github.com/plotly/plotly.py,为了在JupyterLab 中正确渲染plotly,需要通过命令安装特殊扩展

jupyter labextension install jupyterlab-plotly@4.14.3

答案 2 :(得分:0)

尝试安装jupyterlab破折号,对我有用!

您可以通过jupyterlab菜单或按照以下说明进行操作。

https://github.com/plotly/jupyterlab-dash

您似乎也应该升级您的plotly,因为plotly express现在已经是plotly的一部分,即

  const result = [arr[0]];

  arr.reduce((acc, cur, i) => result[i] = acc + "/" + cur);

答案 3 :(得分:0)

我遇到了同样的问题,但原因不同,需要不同的解决方案。只是想分享给遇到同样问题的人。

我在尚未安装 nodejs 或 npm 的 Docker 容器中运行 jupyterlab。

我无法通过以下方式安装所需的扩展:

jupyter labextension install jupyterlab-plotly

因为它给了我这个错误:

ValueError: Please install nodejs and npm before continuing installation. nodejs may be installed using conda or directly from the nodejs website.

Conda 在容器上不可用,当通过 jupyterlab 终端(通过 pip 或 apt-get)安装 node 和 npm 时,我遇到了同样的错误,或者版本不匹配(使用 apt-get 时,我得到的 nodejs 版本是太旧了)。

以下步骤帮助我解决了问题。

  • 构建容器时在docker容器中安装nvm,因此在Dockerfile中:
    • RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
    • 注意版本号,您可能希望将其更改为最新的稳定版本
  • 通过加载一些包含的初始化脚本使 nvm 命令可用:
    • SHELL ["bash", "-lc"] <-- 仅当您的容器尚未使用 bash 作为 shell 时才需要
    • RUN export NVM_DIR="$HOME/.nvm"
    • RUN [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    • RUN [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  • 通过 nvm 安装特定的 nodejs 版本:
    • RUN nvm install 14.17.0
    • 再次注意版本号,更改为您需要的任何版本。
  • 安装 jupyter 扩展:
    • RUN jupyter labextension install jupyterlab-plotly

重新启动内核并愉快地绘图;)

如果这对您的用例有意义,您也可以考虑通过 conda 安装 conda 和 nodejs。不过我还没有测试它是否有效。