6

I wanted to change my python compiler to "newer" one (within one project) and use some additional packages with conda. After the installation all my packages worked fine and I could use the console, however matplotlib.pyplot fails to import since then. And throws the following error: app = QtGui.QApplication([" "]) AttributeError: module 'PyQt5.QtGui' has no attribute 'QApplication'

After doing some research on this I found this one: link It is suggesting to change inputhooks.py (on line 513 and change GUI_QT:enable_qt4 to GUI_QT: enable_qt5 4 to 5) As it is a company machine, I can't have admin rights to overwrite things within PyCharm.

Can you recommend a better solution to avoid this?

Why is this popping up? ErrorLogScreenshot

Also I tried to install the newer version of pyqt but that didn't fix the problem.

In the same time Within pydev the interactiveshell.py fails as well. with the following error message:self.showtraceback(running_compiled_code=True) TypeError: showtraceback() got an unexpected keyword argument 'running_compiled_code' I understand it gets an argument which it is not expecting. I did some research on this one as well and some could fix it by deleting a stale a corresponding .pyc file (I couldn't find one at the same location as the initial file only interactiveshell.py)

Below this blog regarding pydev the conversation never went further https://github.com/ipython/ipython/issues/10687

Is there a way to fix it? I am kind of new to Python and don't quite understand the heart of it at this depth so any help is appreciated.

Thanks, Anna

Anna Semjén
  • 787
  • 5
  • 14
  • I can’t seem to find the typo it was all copy pasted ( from the error message) please don’t downvote for no reason. I would really like to get some help here - did my research and articulated the question clearly! – Anna Semjén May 07 '18 at 21:23

2 Answers2

1

After updating PyCharm all issues seem to have been resolved. (I was using versin 2017.1) The show traceback error was due to pydev, and the new release fixes it.

As well as the GUI problem.

I was able to solve it by finding the file, and both messages disappeared, and matplotlib seems to work fine again.

Under this folder (I named my environment py35):

C:\Users\myusername\AppData\Local\Continuum\anaconda3\envs\py35\Lib\site-packages\IPython\core__pycache__

I found the file: interactiveshell.cpython-35.pyc and deleted it - (This solves the problem only on Python 3.5)

Anna Semjén
  • 787
  • 5
  • 14
1

For anyone having the same issue, I have solved this problem by switching to qt and pyqt 4. To do so, follow the following procedure:

conda remove qt   
conda install qt=4
conda install -c anaconda pyqt=4.11.4
conda install matplotlib --no-update-dependencies

If you are not using a virtual environment, you might also have to remove anaconda navigator before installing new packages:

conda uninstall anaconda-navigator

At the beginning of your program, switch matplotlib backend:

import matplotlib.pyplot as plt
plt.switch_backend('Qt4Agg')

Inspired by this solution.

Sep
  • 347
  • 3
  • 13
  • 2
    ^ This didn't work for me and I had to make a new environment all over again. Simpler solution is either downgrade your matplotlib to matplotlib-2.2.3 or update your pycharm! – JennyStat Mar 08 '19 at 01:41