2

imports not resolving

I am getting a red squiggly line while importing from plotly module even though when I run this script from inside PyCharm (Ctrl-Shift-F10) it works and shows the graph in the web browser. Even ipython shows auto completion for imports:

ipython

This is how my virtualenv looks:

virtualenv

This problem seems to have occurred before: Python dynamic objects not defined anywhere? (Plotly lib)

2 Answers 2

2

After drilling into the imports a bit I found that the __init__.py file in the graph_objs package was too large for default intellisense.
Adding idea.max.intellisense.filesize=10240 to the custom properties file (Help -> Edit Custom Properties...) got it working for me.

Sign up to request clarification or add additional context in comments.

1 Comment

I had this problem when upgrading from Plotly 3 to Plotly 4 when using import plotly.graph_objects as go. This seems to have fixed the problem for now.
0

The short answer: Scatter and Layout objects created dynamicly. Therefore pycharm cannot find its definition.

Details:

This is the first include in your py file;

from plotly.graph_objs import Scatter, Layout

after that it call plotly/graph_objs/__init__.py file ;

from plotly.graph_objs.graph_objs import *  # this is protected with __all__

after that

__all__ = list(graph_reference.CLASSES.keys())

This defination is in plotly/graph_objs/graph_objs.py file. __all__ is a list of public objects of that module.

https://docs.python.org/2/tutorial/modules.html#importing-from-a-package

defination of CLASSES in plotly/graph_referance.py;

CLASSES = _get_classes()

In this function it itarates variable named _BACKWARDS_COMPAT_CLASS_NAMES and create classes;

_BACKWARDS_COMPAT_CLASS_NAMES = {
    ...
    'Scatter': {'object_name': 'scatter', 'base_type': dict},
    ...
    'Layout': {'object_name': 'layout', 'base_type': dict},
    ...
}

2 Comments

So is there a way to get PyCharm to not mark this as a warning?
I try it in Pycharm 2016.2.3, the problem does not continue. I think it can be fixed in current version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.