25

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.

9 Answers 9

21

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.

5
  • 1
    Since @LeonAvery mentioned he is a newbie it is worth mentioning that Import should be import.
    – Greg
    Aug 11, 2013 at 20:12
  • Thanks, Greg -- I made that mistake but figured it out for myself :-) It's version 0.13.2. So I guess anaconda doesn't yet have 1.0.0. I see where I can download that, but I'm not sure how to install it. Do I just unzip it and 'cd <folder>; python setup.py'? Will conda get confused about what I have installed?
    – Leon Avery
    Aug 11, 2013 at 20:27
  • 3
    Consider print(IPython.sys_info()) in Python3 Jan 19, 2018 at 18:36
  • 5
    I am using Jupyter Notebook with ipython version 7.0.1, but same error appears to me.
    – Asif Khan
    Oct 18, 2018 at 12:17
  • I had to issue the pip3 install --upgrade ipython command since the version installed was 5.5 for some reason. Jan 9, 2021 at 12:46
6

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

0
5

if you run the notebook through shell, try the command

ipython notebook --pylab=inline
0
3

Maybe your code is wrong:
%matplotlib.inline

The correct one is:
%matplotlib inline

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 2, 2022 at 1:31
1

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.

1
  • You should provide the link for the OP to get easy_install rather than just telling him what to google.
    – sodd
    Aug 12, 2013 at 9:09
1

If you run the notebook through shell, try the command

ipython notebook --pylab=inline 

It works for me.

0

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.

0

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.stack.imgur.com/QeA5d.png

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

-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.