question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IPython magics no longer work in Spyder 4

See original GitHub issue

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

If we have ipython magic commands in the editor, running them with shift+enter no longer works with Spyder 4

%who print
# %%

runcell(0, 'C:/users/mark/git/vispy/vispy/app/untitled1.py')
  File "C:\users\mark\git\vispy\vispy\app\untitled1.py", line 1
    %who print
    ^
SyntaxError: invalid syntax

image

What is the expected output? What do you see instead?

It used to work in Spyder 3, has the decision been made to revert things?

Versions

  • Spyder version: 4.0.0
  • Python version: 3.7.3 64-bit
  • Qt version: 5.12.5
  • PyQt version: 5.12.3
  • Operating System name/version: Windows / Linux

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:39 (25 by maintainers)

github_iconTop GitHub Comments

3reactions
ccordoba12commented, Dec 12, 2019

IPython magics are not valid Python code, so we decided to not support them anymore in Python files. That will avoid the common problem of files that work in Spyder but not outside of it.

If you want to keep using them, you need to run them like

from IPython import get_ipython
get_ipython().magic('who print')

I think @impact27 added support for .ipy files, i.e. IPython script files. In those files you can use magics freely.

1reaction
hmaarrfkcommented, Dec 14, 2019

and activate the option called Copy full cell contents to the console when running code cells.

I guess I’m trying to say that I’ve seen 4/4 users of Spyder 3 migrate to Spyder 4 and been tripped up by this behavior.

People posting on this thread are to say the least, pretty advanced users of python/spyder. This isn’t the norm.

I agree with your desire to help people write better code, but I would consider this a breaking change in the user experience, and some kind of guidance would be helpful.

It seems that you would prefer users not to use Copy full cell contents to the console when running code cells, but rather to save their files as ipy to keep them portable.

A little guidance will go a long way.

Changing how code is excuted (copied or now) can be ignored. The fact that scripts developed in spyder no longer work with spyder is not really fun.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use IPython magic commands within the Spyder editor?
Firstly, you can open the ipython qtconsloe in the CMD. If you don't open it, the model of ipython is lack in the...
Read more >
Built-in magic commands — IPython 8.7.0 documentation
To work properly, Magics must use a syntax element which is not valid in the underlying language. For example, the IPython kernel uses...
Read more >
Interactive work — rpy2 3.5.4 documentation
This module contains a number of experimental features, some of them no longer necessary since the “R magic” extension for ipython. They are...
Read more >
rmagic — IPython 2.4.2-maint documentation
The rmagic extension has been moved to rpy2 as rpy2.interactive.ipython . Magic command interface for interactive work with R via rpy2. Note. The...
Read more >
Re: [spyder] %paste not working in IPython kernel
%paste magic is only defined for the terminal version of IPython, not for its graphical frontends (i.e. the notebook and qtconsole) because
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found