0

I want to use pycharm as ide, however when i import matplotlib.pyplot as plt in the pycharms python console i get the following error message:

Traceback (most recent call last):
  File "/home/riechers/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-5-a0d2faabd9e9>", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/snap/pycharm-community/155/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/riechers/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2362, in <module>
    install_repl_displayhook()
  File "/home/riechers/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 126, in install_repl_displayhook
    ip.enable_gui(ipython_gui_name)
  File "/snap/pycharm-community/155/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 155, in enable_gui
    return real_enable_gui(gui, app)
  File "/snap/pycharm-community/155/helpers/pydev/pydev_ipython/inputhook.py", line 536, in enable_gui
    return gui_hook(app)
  File "/snap/pycharm-community/155/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'

using ipython in the shell, there is no problem when executing the very same command. I made sure pycharm uses the correct python version as interpreter.

Olmo
  • 325
  • 4
  • 13
  • If you're using a virtual environment you need to install the matplotlib module through the pycharm console, as the python interpreter is not the same executed by your OS in the default directory, it's a separate one stripped of all the modules you've previously installed. – Michele Bastione Oct 08 '19 at 13:44
  • thanks for your answer, however I doubt whether this is the problem here. Pycharm is able to load matplotlib (without .pyplot), in general. For example `import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt` works without an error, but then i cannot use plt.show() – Olmo Oct 08 '19 at 14:00
  • What if you try `from matplotlib import pyplot as plt`? – Michele Bastione Oct 08 '19 at 14:10
  • same error as above :( – Olmo Oct 08 '19 at 14:26

1 Answers1

0
import matplotlib
matplotlib.use('TkAgg')  
import matplotlib.pyplot as plt

https://stackoverflow.com/a/58205465/12343965

  • 2
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes – Pouria Hemi Nov 05 '20 at 12:32