Circular import pyqtgraph

168 views
Skip to first unread message

Tudor Andrei Oancea

unread,
Aug 22, 2022, 9:12:33 AM8/22/22
to pyqtgraph
Hello there,

I am new to pyqtgraph and cannot run basic examples like the following one (found in their documentation):

import pyqtgraph as pg
import numpy as np

x = np.linspace(0.0, 2 * np.pi, 1000)
y = np.sin(x)
pw = pg.plot(x, y, pen="r") # plot x vs y in red

I get the following error:
Traceback (most recent call last):
  File "/Users/tudoroancea/Developer/racing-team/data_visualization/work/pyqtgraph.py", line 2, in <module>
    import pyqtgraph as pg
  File "/Users/tudoroancea/Developer/racing-team/data_visualization/work/pyqtgraph.py", line 9, in <module>
    pw = pg.plot(x, y, pen="r")  # plot x vs y in red
AttributeError: partially initialized module 'pyqtgraph' has no attribute 'plot' (most likely due to a circular import)

However, when I run the examples provided with pyqtgraph during installation it works just fine.
I am using pyqtgraph v0.12.4, and tried with both qt5 and qt6, and with both PySide and PyQt.
Do you have any idea where the problem might come from?

Patrick

unread,
Aug 22, 2022, 10:01:59 PM8/22/22
to pyqtgraph
Hi,

You could try renaming your example file from pyqtgraph.py to something else (eg. test_pyqtgraph.py), it's likely that the "import pyqtgraph as pg" is then trying to import your example pyqtgraph.py file again (as it is in the script directory and thus will be the first match found), which is exactly the definition of a circular import.

Patrick
Reply all
Reply to author
Forward
0 new messages