Don Smythe
Don Smythe

Reputation: 9804

Eclipse PyDev import error

I am trying to use pyqtgraph in PyDev. I can display a plot window within an application using:

import pyqtgraph as pg

However when I try to embed a widget inside a PyQt application using:

from pyqtgraph import PlotWidget

I get a ImportError: cannot import name 'PlotWidget'

I am using a virtualenv with python3 and pyqtgraph installed in the site-packages. The python interpreted libraries includes the python3 site-packages where pyqtgraph is located.

The exact same code I am trying in PyDev works fine in PyCharm using the same virtualenv.

I added the text pyqtgraph to window-preferences-PyDev-Interpreters-Forced Builtins.

I tried 'Force restore internal info' button on the PyDev-PYTHONPATH settings dialog.

I also tried on project RMB-PyDev-Remove Project Config. The made into PyDev project again, File-Restart, Close project, Open Project.

And I tried adding the site-packages/pyqtgraph folder to the External Libraries in the PYTHONPATH.

In addition I then added to the code:

import sys
sys.path.append("/work/.virtualenvs/python3virt/lib/python3.4/site-packages/pyqtgraph")

before the import block shown below. I can see that /work/.virtualenvs/python3virt/lib/python3.4/site-packages/pyqtgraph is clearly on the system path, but get the error ImportError: No module named 'pyqtgraph.widgets'

Curiously sometimes hitting F3 while hovering over pyqtgraph in the import statements will go to the source, other times it wont. For example in the following code, F3 works on the second pyqtgraph import only:

import pyqtgraph as pg
try:
    from pyqtgraph import PlotWidget
except ImportError:
    import sys
    print ('Executable:', sys.executable)
    print ('\n'.join(sorted(sys.path)))
    raise

Does anyone have any ideas on how to get PyDev to recognize the internals of pyqtgraph?

Upvotes: 1

Views: 980

Answers (2)

Fabio Zadrozny
Fabio Zadrozny

Reputation: 25332

Actually, if you just did "pip install pyqtgraph" and installed it in the interpreter everything should work smoothly... if you do want to have it separate from the site-packages though, then you can really add it as an external library source folder, but the proper directory to add in this case is the one that should be in the PYTHONPATH (i.e.: only "pyqtgraph-0.n.n" and not pyqtgraph-0.n.n/pyqtgraph).

Actually, from your install, you probably shouldn't change anything as /work/.virtualenvs/python3virt/lib/python3.4/site-packages is already in the PYTHONPATH -- and /work/.virtualenvs/python3virt/lib/python3.4/site-packages/pyqtgraph should NOT be added separately to the PYTHONPATH.

Also, you shouldn't add it to sys.path in runtime as adding it an external source folder or placing it into the site-packages should be enough.

Upvotes: 2

Don Smythe
Don Smythe

Reputation: 9804

RMB on the project, select PyDev - PYTHONPATH. Select External Libraries, add source solder then select the local pyqtgraph-0.n.n/pyqtgraph folder

Upvotes: 0

Related Questions