无法使用 pycharm 加载 matplotlib.pyplot [英] cannot load matplotlib.pyplot with pycharm

查看:122
本文介绍了无法使用 pycharm 加载 matplotlib.pyplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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'

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

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.

推荐答案

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

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

这篇关于无法使用 pycharm 加载 matplotlib.pyplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆