5

I can't use the debugger in ipython after importing anything pyqt related.

If I don't import anything and debug an error post-mortem like

$ ipython3

In [1]: abc
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-03cfd743661f> in <module>
----> 1 abc

NameError: name 'abc' is not defined

In [2]: %debug
> <ipython-input-1-03cfd743661f>(1)<module>()
----> 1 abc

ipdb> 

all is well, but if I start ipython3 with the pyqt5 backend I get

$ ipython3 --pylab=qt5

In [1]: abc
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-03cfd743661f> in <module>
----> 1 abc

NameError: name 'abc' is not defined

In [2]: %debug
> <ipython-input-1-03cfd743661f>(1)<module>()
----> 1 abc

ipdb> QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0x2105860), parent's thread is QThread(0x1ccc6c0), current thread is QThread(0x7fe7940021f0)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0x2105860), parent's thread is QThread(0x1ccc6c0), current thread is QThread(0x7fe7940021f0)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0x2105860), parent's thread is QThread(0x1ccc6c0), current thread is QThread(0x7fe7940021f0)
QObject: Cannot create children for a parent that is in a different thread.
[...]

I am not developing with qt, I only use it as the backend for matplotlib. I know that this question is very vague, but I don't know where to look for a solution.

I'm on Ubuntu 18.04, Python 3.6.9, ipython 7.14.0, pyqt5 5.14.2.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
clemisch
  • 967
  • 8
  • 18

2 Answers2

1

The problem is resolved with upgrading the pip package "prompt_toolkit" via

$ pip3 install --upgrade prompt_toolkit  # optionally --user 

For me it went from version 2.0.10 to 3.0.5.

clemisch
  • 967
  • 8
  • 18
  • As of mid-August 2020, prompt_toolkit is now at 3.0.6. That did NOT work for me, but 3.0.5, as at the time of this post, resolved the issue for me. – jdmcbr Aug 17 '20 at 18:22
0

As far as your problem is concerned, I have made a couple of searches around that specific error and I have found that this error entirely belongs to ipyhton as the same kind of issues have been already available on ipython official github-issues as given here:

I was also struck with the same problem but I have alternatives. I have performed a couple of tests to debug using ipython. Here are some combinations that can resolve your problem.

 - Either by using 
 ~$ ipython --pylab=qt5

 - Or by using 
 ~$ ipython3 --pylab=qt4

Update


You can use either of these methods to get your work done. But make sure, you have follow all of the given steps one by one.

Method.1

  • Using ipython --pylab=qt5

For this, open your terminal and run the following commands:

~$ sudo killall apt apt-get
~$ sudo rm /var/lib/apt/lists/lock && sudo rm /var/cache/apt/archives/lock && sudo rm /var/lib/dpkg/lock* && sudo dpkg --configure -a && sudo apt update

After that, you have to install these things as follows:

~$ sudo apt install libcanberra-gtk-module libcanberra-gtk3-module 
~$ sudo apt-get install python-pip
~$ pip install ipython
~$ sudo apt-get install python-pyqt5
~$ pip install pyside2 && pip install matplotlib

After installing all of these modules, just run this command: ipython --pylab=qt5, you will see with few exceptions, ipython process will be instantiated.


Method.2

  • Using ipython3 --pylab=qt4

For this, open your terminal and run the following commands:

~$ sudo killall apt apt-get
~$ sudo rm /var/lib/apt/lists/lock && sudo rm /var/cache/apt/archives/lock && sudo rm /var/lib/dpkg/lock* && sudo dpkg --configure -a && sudo apt update

After that, you have to install these things as follows:

~$ sudo apt install libcanberra-gtk-module libcanberra-gtk3-module 
~$ sudo apt-get install python3-pip
~$ pip3 install ipython3
~$ sudo apt-get install python3-pyqt4
~$ pip3 install pyside2 && pip3 install matplotlib

After installing all of these modules, just run this command: ipython3 --pylab=qt4, you will see ipython process will be instantiated.


Now, you can use either of the above-given techniques to use it as the backend for matplotlib. Here is the output of one of the tests from the above techniques:

  • using ipython3 --pylab=qt4

enter image description here

Muhammad Usman Bashir
  • 1,441
  • 2
  • 14
  • 43
  • Thank you for your answer and looking into this! Sadly I have the same problem with qt4. Concerning `ipython`, maybe it works for you because it starts an Python 2 shell instead of Python 3? This is unfortunately not an option for me. – clemisch Jun 04 '20 at 12:41
  • Then you should update your `Sudo` and re-install this stuff. I hope that would work. I have to update everything before performing the tests. I Hope, my efforts would be appreciated. Let me know, how can I further help you? – Muhammad Usman Bashir Jun 04 '20 at 12:55
  • Thank you, but that also does not fix the problem. – clemisch Jun 04 '20 at 19:26
  • @clemisch Can we arrange a *Zoom* Chat? Let me jump into your machine to resolve your issue. – Muhammad Usman Bashir Jun 04 '20 at 22:52
  • I appreciate the offer, but no. If this problem would be solved by updating all packages I would not have posted a SO question. – clemisch Jun 05 '20 at 09:04
  • This issue is due to `ipython` itself. You don't have to worry about that. But these alternatives are working fine, as I have tested same techniques on *two other machines* of my colleagues using the same specs you have given on `github`. – Muhammad Usman Bashir Jun 05 '20 at 14:29
  • What OS are you running? I don't have installation candidates for neither `python3-pyqt4` in apt nor `pyqt4` in pip for Ubuntu 18.04. – clemisch Jun 06 '20 at 11:43
  • I am using `Ubuntu 18.04` as my OS. Run these two commands and give me the output of your python `sys_version`. 1. `python -c "import IPython; print(IPython.sys_info())"`, 2. `python3 -c "import IPython; print(IPython.sys_info())"`. – Muhammad Usman Bashir Jun 06 '20 at 11:50
  • @clemisch I have updated my answer. You can revisit and let me know if you still get some errors. – Muhammad Usman Bashir Jun 06 '20 at 12:30