[英]Unable to import package: Issues with InputHookManager
I have now spent the last hour or so trying to fix this issue but failed.我现在花了最后一个小时左右试图解决这个问题,但失败了。 I have read several related questions such as this , GitHub issues such as this but can't find how to best solve this issue.
我已经阅读了几个相关的问题,比如这个,GitHub 问题,比如这个,但找不到如何最好地解决这个问题。
Steps leading to the error导致错误的步骤
import matplotlib.pyplot as plt
Error message:错误信息:
AttributeError: 'InputHookManager' object has no attribute '_stdin_file'
AttributeError: 'InputHookManager' object 没有属性 '_stdin_file'
EDIT编辑
from matplotlib import pyplot as plt
Failed attempts失败的尝试
I then opened the file that defines InputHookManager and noticed that it had something to do with ipython
and pydev
so I reinstalled ipython
but that didn't solve the issue.然后我打开了定义 InputHookManager 的文件,发现它与
ipython
和pydev
,所以我重新安装ipython
,但这并没有解决问题。
I also tried reinstalling matplotlib
to no avail.我还尝试重新安装
matplotlib
无济于事。 The same error happens with seaborn
presumably because they both need to use gtk3. seaborn
出现同样的错误,大概是因为它们都需要使用 gtk3。
More details about the system有关系统的更多详细信息
python 3.6
pycharm community 2019.2.1
Ubuntu 18.04.3
matplotlib 3.1.1
If IPython didn't work, try the following.如果 IPython 不起作用,请尝试以下操作。 PyCharm seems unhappy with the interactive mode in Linux.
PyCharm 似乎对 Linux 中的交互模式不满意。
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
try this one it worked for me:试试这个对我有用的:
from matplotlib import pyplot as plt
After wasting a lot of time and trying out different IDEs, I finally solved it as follows:在浪费了很多时间尝试了不同的IDE之后,我终于解决了如下:
Assumptions:假设:
Now uninstall ipython
with the default pip
as follows:现在使用默认的
pip
卸载ipython
,如下所示:
sudo python -m pip uninstall ipython
It will throw an error if ipython
doesn't exist(good).如果
ipython
不存在(好),它会抛出一个错误。
Now, install ipython
:现在,安装
ipython
:
sudo python -m pip install ipython
My understanding is that PyCharm is somehow using the default matplotlib
(python 2.7) instead of the project specific interpreter package( matplotlib
from python 3.6 here). My understanding is that PyCharm is somehow using the default
matplotlib
(python 2.7) instead of the project specific interpreter package( matplotlib
from python 3.6 here). You could therefore possibly solve this by resolving that conflict.因此,您可以通过解决该冲突来解决此问题。
I have exactly the same problem.我也有完全一样的问题。 I am on Ubuntu 18.04 using PyCharm 2020.2.
我在 Ubuntu 18.04 上使用 PyCharm 2020.2。 Take a look at: "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure."
看一下: “UserWarning:Matplotlib目前正在使用agg,这是一个非GUI后端,所以无法显示图。” when plotting figure with pyplot on Pycharm
在 Pycharm 上使用 pyplot 绘制图形时
sudo apt-get install python3-tk
solves the problem sudo apt-get install python3-tk
解决问题
20200902 update: unfortunately I see this error again. 20200902 更新:不幸的是,我再次看到此错误。 This seems to fix:
这似乎可以解决:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
plt.show() now can show plots plt.show() 现在可以显示图
I had the exact same problem, the only solution worked for me is to install PyQt5 pip3 install PyQt5
, after the installation, it works like a charm again.我遇到了完全相同的问题,唯一对我有用的解决方案是安装 PyQt5
pip3 install PyQt5
,安装后,它再次像魅力一样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.