plotly / plotly/plotly.py

when running additonal jupyter kernels, jupyterlab extension must be installed in the default environment

未关闭
#2,875 1 条评论 4 个 reaction 已指派 1 人 在 GitHub 查看

@LiamConnors 已经在做这个了。

开始于 2024年7月8日。

documentation P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

Currently, the docs for jupyterlab support (e.g. here or here) imply that the user installs both jupyter, plotly, and the jupyterlab-plotly extension in the same python environment.

In jupyter, users can register existing python environments that are then available as additional kernels to run notebooks on. This helps users avoid running jupyter notebooks on the python environment serving the jupyterlab instance or to install jupyter in every python instance they want to run jupyter notebooks in. In my experience, users often have one environment to start the jupyter server in, and then several different kernels for different projects they are working on.

If a user is expecting to install and use plotly in such a setup (1 python environment for jupyter, a separate one to run plotly in) then she needs to install the jupyterlab-plotly extension (and therefore jupyter itself) in both environments. This is not necessarily intuitive and doesn't fail in a very explicit way if done incorrectly (e.g. here).

edit: This is not actually true. Only the environment running the jupyter server needs the jupyterlab-plotly extension. The environment executing inside jupyterlab only needs nbformat as an additional dependency. This is correctly raised by ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed. So the only case that may be unintuitive is if the user, incorrectly, installs the jupyterlab-plotly extension in the environment used to execute inside jupyter but not in the one serving jupyter. In this case, figures remain blank.

Setup

I set up 4 conda environments that either have or do not have the jupyterlab-plotly extension installed: 2 to run the jupyter server and 2 to install and run plotly inside a jupyter lab instance:
edit: the below example is not correct. Only the server environment needs the jupyterlab-plotly extension. The processing environment needs nbformat, but no extensions.

serv-no

Plain jupyter server environment as it might be installed by following the jupyter docs

conda create -n serv-no jupyter jupyterlab -y
serv-yes

Same as serv-no, but also includes the jupyterlab-plotly extension

conda create -n serv-yes jupyter jupyterlab "ipywidgets=7.5" -y
conda activate serv-yes
jupyter labextension install jupyterlab-plotly@4.12.0
conda deactivate
proc-no

plain environment with plotly installed, but no jupyterlab-plotly extension. Needs ipykernel to register the kernel with the jupyter notebook server. Needs python=3.8 because ipykernel not yet available for 3.9.

conda create -n proc-no python=3.8 -y
conda install -n proc-no -c plotly plotly=4.12.0 ipykernel pandas -y
conda activate proc-no
python -m ipykernel install --user --name procno --display-name "proc-no"
conda deactivate
proc-yes

Same as proc-no, but also installed jupyterlab and jupyterlab-plotly extension edit: nbformat

conda create -n proc-yes python=3.8 -y
conda install -n proc-yes -c plotly plotly=4.12.0 ipykernel pandas jupyterlab -y
conda activate proc-yes
python -m ipykernel install --user --name procyes --display-name "proc-yes"

jupyter labextension install jupyterlab-plotly@4.12.0

edit: this environment only needs nbformat to work as expected. The reason the above example works is because installing jupyter also installs nbformat. But jupyter is not needed in the processing environment. This is correctly explained by raised ValueError. So instead we can just do:

conda install nbformat -y

Reproduce

  1. source server environment, e.g.: conda activate serv-no
  2. start jupyterlab jupyter lab
  3. select a kernel, e.g. proc-yes
  4. run any plotting example from the plotly docs, e.g.
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()

server-no

edit: this example fails, but only because the server environment is missing the jupyterlab-plotly extension.

Outcome

proc-no does not have extension edit: nbformat proc-yes has extension edit: nbformat
serv-no does not have extension 🤷‍♀️ (doesn't work, not expected to, edit: but the error message also doesn't point to the underlying problem): ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed 😭 (doesn't work, probably not expected to edit: user got the installation backwards): Blank Figure / Doesn't get rendered / no error message
serv-yes has extension 😭 (doesn't work, could reasonably be expected to work): ValueError: Mime type rendering requires nbformat>=4.2.0 but it is not installed edit: all that is needed to fix is in the error message 👍 All is good

I think two possible fixes would be:
1. Add a warning or note to the docs, that the installation instructions assume that jupyter, the extension, and plotly are installed in the same environment and that things can break if not
2. Add a section to the docs for multi-kernel setups that clarifies that the installation of jupyter and the extension needs to also be done in the environment that will run plotly edit: that the extension must be installed for the server environment for plotly to work correctly.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。