2

Hi I am using Ubuntu: and Pycharm latest version(2019.2): if i import only matplotlib it does not show any error, however if i try to execute matplotlib.pyplot as plt it shows me below error: Please refer the note section below

import matplotlib.pyplot as plt
Backend GTK3Agg is interactive backend. Turning interactive mode 
on.
Traceback (most recent call last):
File "/home/sarfi/.local/lib/python3.7/site- 
packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-a0d2faabd9e9>", line 1, in <module>
import matplotlib.pyplot as plt
File "/snap/pycharm- 
community/143/helpers/pydev/_pydev_bundle/pydev_import_hook.py", 
line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/sarfi/.local/lib/python3.7/site- 
packages/matplotlib/pyplot.py", line 2362, in <module>
install_repl_displayhook()
File "/home/sarfi/.local/lib/python3.7/site- 
packages/matplotlib/pyplot.py", line 126, in 
install_repl_displayhook
ip.enable_gui(ipython_gui_name)
File "/snap/pycharm-community/143/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 146, in enable_gui
return real_enable_gui(gui, app)
File "/snap/pycharm-community/143/helpers/pydev/pydev_ipython/inputhook.py", line 536, in enable_gui
return gui_hook(app)
File "/snap/pycharm-community/143/helpers/pydev/pydev_ipython/inputhook.py", line 413, in enable_gtk3
self.set_inputhook(create_inputhook_gtk3(self._stdin_file))
AttributeError: 'InputHookManager' object has no attribute '_stdin_file'

NOTE: I tried uninstalling matplotlib and pip3 and reinstalled it, I also installed the Six : pip3 install Six, however, the issue remains the same

4
  • This is an internal pycharm error. You can contact pycharm support about it. Commented Jul 29, 2019 at 20:30
  • Thank you! I have queried them lets see what they have to say on this. Commented Jul 29, 2019 at 21:10
  • This is the reply from pycharm Commented Aug 1, 2019 at 19:46
  • Hi Sarfisayyad, thank you for contacting PyCharm support. The problem is known youtrack.jetbrains.com/issue/PY-16043, unfortunately, it was not yet addressed. I will ping the responsible developer about the ETA. Meanwhile, please vote for the ticket. Pavel, PyCharm QA Engineer Commented Aug 1, 2019 at 19:47

2 Answers 2

0

Here's a workaround: Use a different backend (from gtk/gtk3)

import matplotlib                #only import mpl first
matplotlib.use("agg")            #then set backend
import matplotlib.pyplot as plt 

plt.figure()
plt.plot([1,1])
plt.savefig("name.jpg")

I haven't tested other backends yet, but this works. Of course this is no permanent solution but just a quick emergency fix if you need the figures.

The problem is with gtk/gtk3 (I think). Also shown in PY-16043 Failed to enable GUI event loop integration for 'gtk' (see https://youtrack.jetbrains.com/issue/PY-16043 , which is the link BugsBunny already put).

The Error occurs when the enable_gtk/enable_gtk3 method is defined. So if you don't use this backend, you avoid the error.

Sign up to request clarification or add additional context in comments.

Comments

0

Use:

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt

And it does the trick

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.