Import error matplotlib.pyplot in jupyter (but not ipython)

Update: ipykeynel 4.4.1 fixed this problem on the morning of August 9th.

I have a new version and I'm trying to run my python routines, namely jupyter notebook and matplotlib. I set everything up and the "import matplotlib" works. If I am in a jupyter laptop and I try to "import matplotlib.pyplot" or "from mplotlib import pyplot as plt", I get:

 ImportError Traceback (most recent call last) ... /usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in configure_inline_support(shell, backend) 359 except ImportError: 360 return --> 361 from matplotlib import pyplot 362 363 cfg = InlineBackend.instance(parent=shell) ImportError: cannot import name pyplot 

Full trace

However, if I'm on ipython (command line), this works fine. In addition, graphs are executed from the module from the command line, excellent. I tried various methods:

  • Package install / uninstall matplotlib, ipython and jupyter in different order
  • Using pip with --no-cache-dir and / or -ignore-installed
  • Removing ~ / .cache, ~ / .ipython and ~ / .jupyter
  • Make sure that packages with apt-get are not installed, installed only with a peak
  • Using apt-get to install python-matplotlib, ipython and python-jupyter

It looks like I was looking for some information about the path, but I can’t determine what or where it can happen, especially after deleting / reinstalling a few pip and clearing the cache. I read every SO question related to matplotlib import, none of them helped.

I went back to matplotlib 1.4.3 and it worked, but I am missing a couple of functions that I need. I understand that this is probably difficult, so if you have any ideas, even if they are incomplete, it will be very useful. Also, if this is something worthy of a bug report (never been done, not sure if this is a matplotlib problem or just locally parsed), comment as such and I will post it. Thanks!

System Information:

 Linux Mint 18 "Sarah" Python==2.7.12 ipykernel==4.4.0 ipython==5.0.0 ipython-genutils==0.1.0 ipywidgets==5.2.2 jupyter==1.0.0 jupyter-client==4.3.0 jupyter-console==5.0.0 jupyter-core==4.1.0 notebook==4.2.2 numpy==1.11.1 pip 8.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7) 

The output of sys.path in ipython and jupyter (same for both):

 ['', '/usr/local/bin', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/local/lib/python2.7/dist-packages/IPython/extensions', '/home/mm/.ipython'] 
+7
python matplotlib jupyter-notebook
source share
2 answers

I have the same problem and the problem can be solved by ipykernel. after I returned ipykernel version to 4.3.1. the problem is resolved.

just like @Igor Raush said, this is similar to matplotlib.pyplot import circular.

+5
source share

As mentioned here , using the %matplotlib magic line allows me to use the backend in a new window (Qt4Agg in my case). I did not know that you could use %matplotlib yourself, without an argument. Although upgrading to ipykernel 4.4.1 fixes this problem, I thought the magic linear trick was pretty smart and might fix other import oddities / errors in the future.

+1
source share

All Articles