Leon Avery
Leon Avery

Reputation: 866

ERROR: Line magic function `%matplotlib` not found

I have just installed IPython on a Mac (MacOS 10.7.5) following the instructions for anaconda on http://ipython.org/install.html, with no obvious errors. I now want to work my way through the example notebooks. In notebook "Part 1 - Running Code", everything works as it should until I get to

%matplotlib inline

Then I get the error message

ERROR: Line magic function %matplotlib not found.

Everything after that works, except that plots, instead of appearing inline, pop up in a new window.

Upvotes: 25

Views: 73641

Answers (9)

Arjun M S
Arjun M S

Reputation: 31

Maybe your code is wrong:
%matplotlib.inline

The correct one is:
%matplotlib inline

Upvotes: 3

tanvi
tanvi

Reputation: 35

I had a similar problem on windows. Make sure that you've added Conda and python to the path. To check that you can run the following command on command prompt

jupyter notebook

if it doesnt recognize then go to anaconda prompt and type

where conda where python

refer the image for paths to include [1]: https://i.sstatic.net/QeA5d.png

Add these to the path and mostly youll be good to go

Upvotes: 0

Matt
Matt

Reputation: 27843

Try:

import IPython
print(IPython.sys_info())

Does it report that you are on 'ipython_version' 1.0+? You might be picking up an older version of IPython that do not have the %matplotlib magic.

Upvotes: 21

gandhar_nigudkar
gandhar_nigudkar

Reputation: 9

instead of the inline command, I simply put this after the plot matplotlib.pyplot.show()

Upvotes: -1

jiangzuomei
jiangzuomei

Reputation: 21

If you run the notebook through shell, try the command

ipython notebook --pylab=inline 

It works for me.

Upvotes: 1

Jan Vlcinsky
Jan Vlcinsky

Reputation: 44112

Make sure, you use the right installation of ipython

In my case, I have system-wide Python installation for application development and beside that, also anaconda for data analysis (to be used with ipython notebooks).

When starting ipython notebook, I shall set PATH properly to use anaconda version of ipython.

Forgetting to set PATH, I use system-wide installed ipython which does not serve running notebooks well resulting in the complain about %matplotlib inline as noted in OP.

When I set PATH properly and used anaconda version of python and ipython, all goes well.

Upvotes: 0

irenemeanspeace
irenemeanspeace

Reputation: 301

if you run the notebook through shell, try the command

ipython notebook --pylab=inline

Upvotes: 5

Roger
Roger

Reputation: 61

If you have Anaconda, just do conda update ipython from the command line. No need for removal, easy_install and all the rest.

Upvotes: 6

GeoffB
GeoffB

Reputation: 11

I had this problem on Windows, but I believe it will work the same way:

  1. Get rid of the old IPython. The command is conda remove ipython.
  2. Get easy_install if you don't have it. Follow the instructions to install easy_install for your system.
  3. Use easy_install to reinstall the newest IPython. The command is easy_install ipython[all], just like it shows on the site.

With Conda's default IPython gone, it should indicate it's loading IPython 1.0.0. You can make sure by running either IPython or the IPython Notebook and running the command %lsmagic. If matplotlib is in the list, you've got it.

Upvotes: 1

Related Questions