cannot load matplotlib.pyplot with pycharm

梦想的初衷 提交于 2020-12-15 09:01:21

问题


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.


回答1:


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

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



来源:https://stackoverflow.com/questions/58287088/cannot-load-matplotlib-pyplot-with-pycharm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!