Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to run my code on my computer, but somehow get an error:

File "catcode.py", line 9

%matplotlib inline
SyntaxError: invalid syntax

I am using macOS Sierra 10.12.6, MacBook Pro (Retina, 13-inch, Early 2015), 2.9 GHz Intel Core i5, 8 GB 1867 MHz DDR3, Intel Iris Graphics 6100 1536 MB.

I am also using python 3 through terminal:

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)

[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

This is the list of packages I have:

['appnope==0.1.0', 'cycler==0.10.0', 'decorator==4.1.2', 'h5py==2.7.1', 'ipython-genutils==0.2.0', 'ipython==6.2.1', 'jedi==0.11.0', 'matplotlib==2.1.0', 'numpy==1.13.3', 'parso==0.1.0', 'pexpect==4.2.1', 'pickleshare==0.7.4', 'pip==9.0.1', 'prompt-toolkit==1.0.15', 'ptyprocess==0.5.2', 'pygments==2.2.0', 'pyparsing==2.2.0', 'python-dateutil==2.6.1', 'pytz==2017.2', 'scikit-learn==0.19.0', 'scipy==0.19.1', 'setuptools==28.8.0', 'simplegeneric==0.8.1', 'six==1.11.0', 'traitlets==4.3.2', 'wcwidth==0.1.7']

%matplotlib inline is a "magic function" that decorates a cell in a Jupyter notebook.

You can't use it outside of jupyter notebook, and ipython console

The best solution for you, is probably to comment out the line; other than that, you can install jupyter and ipython.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.