无法使用pycharm

时间:2019-10-08 13:12:37

标签: python matplotlib pycharm

我想将pycharm用作ide,但是当我在pycharms python控制台中import matplotlib.pyplot as plt时,出现以下错误消息:

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'

在外壳中使用ipython,执行相同的命令时没有问题。我确保pycharm使用正确的python版本作为解释器。

1 个答案:

答案 0 :(得分:0)

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

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