pyqt5 and pyqtgraph - Exception on import (most recent changes from github)

1,876 views
Skip to first unread message

Dan

unread,
Nov 12, 2014, 1:37:23 PM11/12/14
to pyqt...@googlegroups.com
I am trying to develop a pretty straightforward application for my lab to use for our data viewing and analysis, and I was hoping to use pyqtgraph in combination with pyqt5 for the plotting aspect of the application.

However, I've run into a hurdle that I can't seem to get over. I'm hoping it's something trivial that I'm missing, as I don't really want to have to go to another plotting library. 

I know that currently that pyqtgraph doesn't officially support pyqt5, but I found the threads discussing the changes necessary with links to versions that are working with pyqt5 (at least, the examples are working). My current installation of pyqtgraph is from the most recent update on github, although I had to go into Qt.py and fix the print statement bug. 

The error that I get when I try to import pyqtgraph is: 


Exception: PyQtGraph requires one of ('PyQt4', 'PySide), but none of these could be imported. PyQt5 was detected, but to use it you you must also install qt_backport. 



I'm using the most recent Anaconda distribution of Python 3. I have installed qt_backport as well as PyQt5 in the environment that I'm using for this. 


I'm not sure what other information is needed to help troubleshoot this, so please let me know how I can further clarify what's going on. 


Thanks

Russell Warren

unread,
Nov 17, 2014, 9:53:49 AM11/17/14
to pyqt...@googlegroups.com
The error that I get when I try to import pyqtgraph is: 

Exception: PyQtGraph requires one of ('PyQt4', 'PySide), but none of these could be imported. PyQt5 was detected, but to use it you you must also install qt_backport. 

qt_backport works by faking out attempted imports of "PySide" or "PyQt4" (You don't actually 'import qt_backport' anywhere).  That error occurs when one of those imports fails with an ImportError.  The second sentence indicates that "import PyQt5" worked, though.

Can you post the traceback of what you get when you just try and "import PySide" in your environment?

Russ

Dan

unread,
Nov 17, 2014, 9:58:47 AM11/17/14
to pyqt...@googlegroups.com
Hi Russ, 

Here's the traceback: 

In[3]: import PySide
Traceback (most recent call last):
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-5d84305db498>", line 1, in <module>
    import PySide
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\PySide\__init__.py", line 8, in <module>
    _qt_backport.emulate(emulator, wrapper)
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\qt_backport\__init__.py", line 71, in emulate
    emulation_dispatcher[(emulator, wrapper)](emulator_module)
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\qt_backport\__init__.py", line 48, in _emulate_pyside_with_pyqt5
    _create_base_qt4_emulator_with_pyqt5(emulator_module)
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\qt_backport\__init__.py", line 33, in _create_base_qt4_emulator_with_pyqt5
    import qt5_backport as _qt5_backport
ImportError: No module named 'qt5_backport'


Thanks for the help. 

 - Dan

Russell Warren

unread,
Nov 17, 2014, 10:15:12 AM11/17/14
to pyqt...@googlegroups.com
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\qt_backport\__init__.py", line 33, in _create_base_qt4_emulator_with_pyqt5
    import qt5_backport as _qt5_backport
ImportError: No module named 'qt5_backport'


That is weird.  qt5_backport should be directly beside the /qt_backport/__init__.py file.  See here:


Check your site-packages folder for that qt5_backport file.  As a hack, try and drop it in directly, although you should *not* need to do this.  If that is broken, what else is?

The relevant folder for you to check on your machine is:

C:\Anaconda3\envs\pyqt5\lib\site-packages\qt_backport\

I just verified that a clean `pip install qt_backport` works perfectly, so I'm not sure why that file is missing for you.  How did you install qt_backport?

Russ

Dan

unread,
Nov 17, 2014, 10:30:55 AM11/17/14
to pyqt...@googlegroups.com
The qt5_backport file is in the qt_backport folder (qt_backport was installed with 'pip install qt_backport')

Dan

unread,
Nov 17, 2014, 10:37:48 AM11/17/14
to pyqt...@googlegroups.com
if I am in the qt_backport folder (just working in the ipython console) and try:

import qt5_backport

I get the same error. I.e.

Traceback (most recent call last):
  File "C:\Anaconda3\envs\pyqt5\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-b8d242f44e70>", line 1, in <module>
    import qt5_backport
ImportError: No module named 'qt5_backport'


Not sure if that's helpful

Dan

unread,
Nov 17, 2014, 10:40:24 AM11/17/14
to pyqt...@googlegroups.com
For some reason I get a different error if I do that from my powershell: 

In [7]: os.chdir(r'C:\Anaconda3\envs\pyqt5\Lib\site-packages\qt_backport')

In [8]: import qt5_backport
  File "C:\Anaconda3\envs\pyqt5\Lib\site-packages\qt_backport\qt5_backport.py", line 217
    print "Can't subclass %s" % cls_name
                            ^
SyntaxError: invalid syntax

Russell Warren

unread,
Nov 17, 2014, 10:52:59 AM11/17/14
to pyqt...@googlegroups.com
In [8]: import qt5_backport
  File "C:\Anaconda3\envs\pyqt5\Lib\site-packages\qt_backport\qt5_backport.py", line 217
    print "Can't subclass %s" % cls_name
                            ^
SyntaxError: invalid syntax

That is normal and is just because you are running python 3.  I didn't make qt_backport python 3 compatible (yet).  At least python is behaving normally there and seeing qt5_backport for import, though!

In your ipython setup it seems like your sys.path is borked and doesn't see local files.

Try this in your ipython shell:

>>> import sys
>>> "" in sys.path
True

I bet you get False, in which case you can do an even bigger hack and try

sys.path.insert(0, "")

in your code (before your pyqtgraph import) to see if it helps with the qt_backport emulator imports.  However, the bigger question would be why your ipython setup dropped dropped "" from sys.path.

Russ

Dan

unread,
Nov 17, 2014, 11:06:21 AM11/17/14
to pyqt...@googlegroups.com
So, the two errors come from running those commands in two different places. 

The first is from within the ipython console within PyCharm

The second is from running ipython in powershell 

"" in sys.path returns False in PyCharm
"" in sys.path returns True in powershell

So I'm guessing that's just a quirk of PyCharm and can be ignored. 


So the seems to simply be that qt_backport is not currently compatible with python 3 (since we can just ignore that first traceback I posted when trying to do import qt5_backport)? 

Russell Warren

unread,
Nov 17, 2014, 12:32:00 PM11/17/14
to pyqt...@googlegroups.com
After some investigation, all of this is a consequence of the absolute path introduction in python 3.  I'm fixing this and will update qt_backport shortly.  I have not migrated to python3 yet so there may be more wrinkles like this (but hopefully not).

Russell Warren

unread,
Nov 17, 2014, 12:54:23 PM11/17/14
to pyqt...@googlegroups.com
I've bumped it to 0.1.3 which should fix the python3 issue(s) seen so far.

Please `pip install -U qt_backport` and let me know if it works out for you!

If it doesn't work, let's take it off-list since this is definitely not a pyqtgraph problem.  As you know, pyqtgraph still doesn't officially support Qt5, and using my qt_backport fork is more than a bit of a hack to make it work. :)  Although it works well for is, my fork has fallen behind pyqtgraph:develop and I've not tried merging it in yet. 
 
Russ

Reply all
Reply to author
Forward
0 new messages