These are chat archives for spyder-ide/public

Jan 2019
Jan 25 09:06

Hi. I'm having a problem with % commands when I use them in my spyder code.
If I use code " %matplotlib inline " for example I get the following error message:
%matplotlib inline
SyntaxError: invalid syntax

From searching for the solution, it seems that the % is an IPython magic commmand and I would therefore need IPython to use code with this command.

I'm using Spyder 3.7 and can open IPython consoles.
Why then is the code not working???

Any help would be greatly appreciated!

  • I'm using Spyder 3.3.2 with Python 3.7
CAM Gerlach
Jan 25 21:46
@iblignic Those % commands are indeed IPython magics, which are only intended to be used interactively (i.e. typed directly into the IPython console), not in your normal Python code. As they only will work in the IPython interpreter and are not designed to function reliably in non-interactive mode, they should not be used in your scripts or modules, even if they did work.
If you want to switch the graphics backend, you can use Spyder's preferences to do so, or type the magic directly into the relevant console.