NelsonGon
NelsonGon

Reputation: 13319

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.

Steps leading to the error

  1. import matplotlib.pyplot as plt

Error message:

AttributeError: 'InputHookManager' object has no attribute '_stdin_file'

EDIT

  1. Importing as follows throws the same error(please see details of my system and failed attempts below):
from matplotlib import pyplot as plt

  1. It works at the Terminal

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.

I also tried reinstalling matplotlib to no avail. The same error happens with seaborn presumably because they both need to use gtk3.

More details about the system

python 3.6
pycharm community 2019.2.1
Ubuntu 18.04.3
matplotlib 3.1.1

Upvotes: 4

Views: 2306

Answers (5)

Albert G Lieu
Albert G Lieu

Reputation: 911

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.

Upvotes: 0

monolingual
monolingual

Reputation: 31

I have exactly the same problem. I am on Ubuntu 18.04 using PyCharm 2020.2. Take a look at:"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm

sudo apt-get install python3-tk solves the problem

20200902 update: unfortunately I see this error again. This seems to fix:

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

plt.show() now can show plots

Upvotes: 2

Ruxiu
Ruxiu

Reputation: 61

If IPython didn't work, try the following. PyCharm seems unhappy with the interactive mode in Linux.

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

Upvotes: 6

NelsonGon
NelsonGon

Reputation: 13319

After wasting a lot of time and trying out different IDEs, I finally solved it as follows:

Assumptions:

  1. You're using a Linux distro(I was using Ubuntu 18.04.3)

Now uninstall ipython with the default pip as follows:

sudo python -m pip uninstall ipython

It will throw an error if ipython doesn't exist(good).

Now, install 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). You could therefore possibly solve this by resolving that conflict.

Upvotes: 1

Ronak Patel
Ronak Patel

Reputation: 26

try this one it worked for me:

from matplotlib import pyplot as plt

Upvotes: 1

Related Questions