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

v0.0.2 cannot import name 'PlotlyScope' on Windows venv #22

Closed
WEGFan opened this issue Jul 26, 2020 · 7 comments · Fixed by #25
Closed

v0.0.2 cannot import name 'PlotlyScope' on Windows venv #22

WEGFan opened this issue Jul 26, 2020 · 7 comments · Fixed by #25
Milestone

Comments

@WEGFan
Copy link

WEGFan commented Jul 26, 2020

>>> from kaleido.scopes.plotly import PlotlyScope
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\My Documents\GitHub\codestats-profile-readme\venv\lib\site-packages\kaleido\scopes\plotly.py", line 4, in <module>
    from plotly.graph_objects import Figure
  File "D:\My Documents\GitHub\codestats-profile-readme\venv\lib\site-packages\plotly\__init__.py", line 34, in <module>
    from plotly import (
  File "D:\My Documents\GitHub\codestats-profile-readme\venv\lib\site-packages\plotly\io\__init__.py", line 5, in <module>
    from ._kaleido import to_image, write_image
  File "D:\My Documents\GitHub\codestats-profile-readme\venv\lib\site-packages\plotly\io\_kaleido.py", line 8, in <module>
    from kaleido.scopes.plotly import PlotlyScope
ImportError: cannot import name 'PlotlyScope'

It seems like it's a circular import problem and #18 causes it, but neither Linux with venv nor Windows without venv has this issue.
I'm using Python 3.6.8 on Windows and 3.6.2 on Linux.

@jonmmease
Copy link
Collaborator

Hi @WEGFan, what version of the plotly package do you have installed in each environment?

@WEGFan
Copy link
Author

WEGFan commented Jul 27, 2020

Both are 4.9.0

@WEGFan
Copy link
Author

WEGFan commented Jul 27, 2020

Oh I forgot to say I add a line in plotly/io/_kaleido.py here to find out what caused the PlotlyScopebe None

try:
    from kaleido.scopes.plotly import PlotlyScope

    scope = PlotlyScope()

    # Compute absolute path to the 'plotly/package_data/' directory
    root_dir = os.path.dirname(os.path.abspath(plotly.__file__))
    package_dir = os.path.join(root_dir, "package_data")
    scope.plotlyjs = os.path.join(package_dir, "plotly.min.js")
    scope.mathjax = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"
except ImportError:
    raise  # here
    PlotlyScope = None
    scope = None

@jonmmease
Copy link
Collaborator

Thanks for info the debugging @WEGFan. I'm not able to reproduce yet, but there is a circular import here that we might as well get rid of.

In kaleido/py/kaleido/scopes/plotly.py, we can move the from plotly.graph_objects import Figure related import down into the transform method.

Here is a PR that does this: #25. Could you give this a try (The change is moving a single line, so you could edit it manually as you did above).

@WEGFan
Copy link
Author

WEGFan commented Jul 27, 2020

It worked, but I still wonder why it happened only in venv...

@jonmmease
Copy link
Collaborator

Great! I'm also not sure what is going on with the virtual environment there.

Until we get the next release out, I'm pretty sure you wouldn't run into this issue if you could use Python 3.7+ in your venv since plotly.py imports submodules, like plotly.io, lazily in this case.

@jonmmease jonmmease added this to the 0.0.3 milestone Jul 27, 2020
@jonmmease
Copy link
Collaborator

This fix has been released in version 0.0.3

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 a pull request may close this issue.

2 participants