Skip to content

If IPython is merely installed, don't assume that it's actually used #5222

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pfalcon
Copy link

@pfalcon pfalcon commented Jun 7, 2025

In my virtual environment, there happens to be installed IPython package. It wasn't installed by myself, it's merely a transitive dependency of some another package. It's neither intended to be used, nor is actually used by my project. However, mere presense of the IPython package, due to the over-simplistic decision code in this module (io._renderers) leads to drastic behavior change in Plotly.py: calling Figure.repr_html() causes lots of JS garbage to be printed on terminal (by common sense, this should be a side-effects free function, only returning a value). On a higher level, this breaks natural Plotly.py integration in frameworks like Shiny.py (because again, instead of HTML representation being returned for a framework to process, parts of that representation are dumped on terminal).

The real underlying issue is that Plotly.py should not force-import any "optional" packages behind users' back. However, this is a deeper issue requiring consideration and will be reported separately. This patch is a quick solution for the problem describe above.

From interactive session:

>>> import IPython
>>> IPython.get_ipython().__class__.__name__
'NoneType'

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

In my virtual environment, there happens to be installed IPython package.
It wasn't installed by myself, it's merely a transitive dependency of
some another package. It's neither intended to be used, nor is actually
used by my project. However, mere presense of the IPython package, due
to the over-simplistic decision code in this module (io._renderers)
leads to drastic behavior change in Plotly.py: calling
Figure._repr_html_() causes lots of JS garbage to be printed on terminal
(by common sense, this should be a side-effects free function, only
returning a value). On a higher level, this breaks natural Plotly.py
integration in frameworks like Shiny.py (because again, instead of
HTML representation being returned for a framework to process, parts
of that representation are dumped on terminal).

The real underlying issue is that Plotly.py should not force-import
any "optional" packages behind users' back. However, this is a deeper
issue requiring consideration and will be reported separately. This
patch is a quick solution for the problem describe above.

From interactive session:

>>> import IPython
>>> IPython.get_ipython().__class__.__name__
'NoneType'

Signed-off-by: Paul Sokolovsky <[email protected]>
@pfalcon
Copy link
Author

pfalcon commented Jun 7, 2025

Example of how this affects downstream projects: posit-dev/py-shinywidgets#201 . I'm an experienced Python user, and it took me half a day to debug this issue. I imagine how frustrating it may be for novice users who just wanted to try one of those well-popularized modern Python data visualization packages.

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

Successfully merging this pull request may close these issues.

1 participant