Skip to content
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

Figure factory broken in release 4.7.0 #2443

Closed
cliffckerr opened this issue May 6, 2020 · 9 comments
Closed

Figure factory broken in release 4.7.0 #2443

cliffckerr opened this issue May 6, 2020 · 9 comments
Labels
bug something broken
Milestone

Comments

@cliffckerr
Copy link

Describe the bug

Related to #1111, import plotly.figure_factory fails with the most recent Plotly release (4.7) without a helpful error message.

To reproduce

First noticed with

conda create -n plotly_test python=3.7.7
conda activate plotly_test
pip install plotly_express
python
>>> import plotly.figure_factory

(which worked until this morning's release), but also reproducible via:

conda create -n plotly_test python=3.7.7
conda activate plotly_test
pip install numpy==1.18.4 plotly==4.7.0
python
>>> import plotly.figure_factory

Expected behavior

It works, or at least gives a helpful error message.

Actual behavior

>>> import plotly.figure_factory
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/software/anaconda3/envs/plotly_test/lib/python3.7/site-packages/plotly/figure_factory/__init__.py", line 14, in <module>
    from plotly.figure_factory._2d_density import create_2d_density
  File "/software/anaconda3/envs/plotly_test/lib/python3.7/site-packages/plotly/figure_factory/_2d_density.py", line 8, in <module>
    from plotly.graph_objs import graph_objs
  File "/software/anaconda3/envs/plotly_test/lib/python3.7/site-packages/plotly/graph_objs/graph_objs.py", line 1, in <module>
    from plotly.graph_objs import *
  File "/software/anaconda3/envs/plotly_test/lib/python3.7/site-packages/plotly/graph_objs/__init__.py", line 290, in __getattr__
    return orig_getattr(import_name)
  File "/software/anaconda3/envs/plotly_test/lib/python3.7/site-packages/_plotly_utils/importers.py", line 41, in __getattr__
    name=import_name, __name__=parent_name
AttributeError: module 'plotly.graph_objs' has no attribute 'FigureWidget'

Workaround

Manually install ipywidgets (e.g., pip install ipywidgets plotly_express works).

Suggested solution

Add ipywidgets back to the plotly_express requirements, and make an ipywidgets error message similar to the one that exists if you try to use figure_factory without having numpy installed.

Platform:

  • OS: Ubuntu 18.04
  • Python: 3.7.7 (observed on Python 3.8 as well, but not on Python 3.6)
@jonmmease
Copy link
Contributor

Thanks for the report @cliffckerr, and thanks for pointing out the workaround of installing ipywidgets.

The underlying issue here is with the from plotly.graph_objs import * statement. FigureWidget shows up in __all__ even when ipywidgets is not installed, so it is picked up by *.

For performance reasons, we don't want to attempt to import ipywidgets when plotly.py is imported. One option might be to return a dummy class in place of FigureWidget when ipywidgets is not installed. This dummy class would raise a missing dependency exception in the constructor.

@emmanuelle
Copy link
Contributor

we could also fix this by changing the imports in _2d_density.py which are a bit weird (why from plotly.graph_objs import graph_objs` ?). I'm surprised our tests did not catch this...

@rysktky
Copy link

rysktky commented May 7, 2020

Is this a same sort of issue?
I can't use subplots unless explicitly import it.

>>> import sys
>>> import plotly

>>> sys.version
'3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]'
>>> plotly.__version__
'4.7.0'

>>> plotly.subplots
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\_plotly_utils\importers.py", line 41, in __getattr__
    name=import_name, __name__=parent_name
AttributeError: module 'plotly' has no attribute 'subplots'

>>> from plotly import subplots
>>> subplots
<module 'plotly.subplots' from 'C:\\Python37\\lib\\site-packages\\plotly\\subplots.py'>
>>> subplots.make_subplots
<function make_subplots at 0x0000023F70199E58>
>>>
>>> plotly.subplots
<module 'plotly.subplots' from 'C:\\Python37\\lib\\site-packages\\plotly\\subplots.py'>
>>>

@jonmmease
Copy link
Contributor

Proposed fix in #2445. @emmanuelle would you have time to take a look?

@cliffckerr
Copy link
Author

Closed by #2445

@nicolaskruchten
Copy link
Contributor

@cliffckerr this is now released as part of 4.7.1!

@cliffckerr
Copy link
Author

Super, thanks @nicolaskruchten !

@leo-smi
Copy link

leo-smi commented Jan 2, 2022

Is this a same sort of issue? I can't use subplots unless explicitly import it.

>>> import sys
>>> import plotly

>>> sys.version
'3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]'
>>> plotly.__version__
'4.7.0'

>>> plotly.subplots
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\_plotly_utils\importers.py", line 41, in __getattr__
    name=import_name, __name__=parent_name
AttributeError: module 'plotly' has no attribute 'subplots'

>>> from plotly import subplots
>>> subplots
<module 'plotly.subplots' from 'C:\\Python37\\lib\\site-packages\\plotly\\subplots.py'>
>>> subplots.make_subplots
<function make_subplots at 0x0000023F70199E58>
>>>
>>> plotly.subplots
<module 'plotly.subplots' from 'C:\\Python37\\lib\\site-packages\\plotly\\subplots.py'>
>>>

this error still occur on plotly 5.5.0, the only way to use it is import like this:

from plotly.subplots import make_subplots

windows 10
python 3.10

@nicolaskruchten
Copy link
Contributor

@leo-smi this is intentional, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

6 participants