Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some magic commands not working in Python Interactive window #3187

Closed
Gorbagzog opened this issue Aug 8, 2019 · 27 comments
Closed

Some magic commands not working in Python Interactive window #3187

Gorbagzog opened this issue Aug 8, 2019 · 27 comments
Assignees

Comments

@Gorbagzog
Copy link

Environment data

VS Code version: 1.36.1
Extension version (available under the Extensions sidebar): 2019.8.29288
OS and version: MAC 10.14.4
Python version: 3.7.1

Expected behavior

Inside the Python interactive window, I want to use magic commands like %magic or the question mark like foo?

Actual behavior

Some magic commands are working (like %history or %pylab), but other do not work, like %magic or %pinfo which is equivalent to the question mark foo?

I understand this might be related to this closed issues: microsoft/vscode-python#4170 microsoft/vscode-python#5565
However the behaviour of some magic functions are not the same inside the Python interactive window compared to an ipython terminal.

I do not know if this issue is from my side, or if it is by design in the Python interactive window, or if it will be solved in a future release.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2019

Not sure why they don't work. Jupyter is giving us nothing back as results for %pinfo or %magic.

These may be client side only commands and we'd have to implement them ourselves.

%pinfo should be easy to workaround though as we have a list of variables at the top of the window.

@dlindelof
Copy link

I'm using this extension and can confirm that iPython's dynamic object information feature (https://ipython.org/ipython-doc/3/interactive/reference.html#dynamic-object-information) doesn't work. For example, len? doesn't show anything:

image

But in plain iPython the function's docstring is shown:

image

Here's my extension information:

Name: Python
Id: ms-python.python
Description: Linting, Debugging (multi-threaded, remote), Intellisense, code formatting, refactoring, unit tests, snippets, and more.
Version: 2019.10.33744-dev
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

@ARF1
Copy link

ARF1 commented Oct 21, 2019

@Axel-Shark
Copy link

Solution / workaround in #7289 (comment)

Just tested. Not a solution.

@ARF1
Copy link

ARF1 commented Oct 23, 2019

@SJWackness Thanks for letting me know.

#3119 probably should not have been marked as a duplicate of this issue...

@rchiodo
Copy link
Contributor

rchiodo commented Nov 20, 2019

This might fix some of the problem. However it doesn't fix it for every command:

import IPython.core
IPython.core.page = print

We need to investigate whether or not this should be part of our default set of code we run on startup.

@aragong
Copy link

aragong commented Dec 5, 2019

Same problem with %time and %%time.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

@aragong What results do you get for %time and %%time? They seem to work for me:

image

@aragong
Copy link

aragong commented Dec 5, 2019

If I use %%time and execute the code using ctrl+enter. UsageError: Line magic function %%time not found.

If I use %%time ans execute the code selecting the lines and pressing shift+enter. Wall time: 1.86 s

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

Can you share your code? This sounds like a different issue. At least CTRL+ENTER and SHIFT+ENTER are supposed to do the exact same thing, but one advances and the other doesn't. For me they both work, but maybe it has something to do with how you're executing.

I'm using code like so:

#%% 
%%time
print('bar')

It also works in a notebook
image

@aragong
Copy link

aragong commented Dec 5, 2019

Please try
#%%

%%time
print('bar')

If you have an empty line does not work for me but your previous code runs perfectly! I'm using a .py file working on Interactive python from miniconda with cells (#%%) I do not know if that helps!

@aragong
Copy link

aragong commented Dec 5, 2019

image

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

Wow, weird. Sorry but that works for me just fine. Perhaps there's extra chars on that line? And CTRL+ENTER doesn't work, but SHIFT+ENTER does? What do you have mapped to CTRL+ENTER? Maybe there is some extra command running too?

@aragong
Copy link

aragong commented Dec 5, 2019

How can I restore default keyboard shortcuts? Maybe the problem is that??

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

Use the open keyboard shortcuts (JSON) command. It should open the JSON file that has your remappings. If you delete everything in there it will reset you back to default.

@aragong
Copy link

aragong commented Dec 5, 2019

It is empty! I do not know what is happening!

image

Ok I've just done this:
A) run each cell with right click --> run cell in Python interactive window. responses [1],[2],[3]
B) run each cell selecting the lines and shift+enter. responses [4],[5],[6]

image

I've no idea what is wrong!!

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

This one actually fails for me:

import time
%%time
print('bar')

But it also fails on Jupyter:
image

So maybe it has something to do with jupyter getting confused over what 'time' actually means?

@aragong
Copy link

aragong commented Dec 5, 2019

clicking on Run Cell button:

image

maybe it is my python environment?

@rchiodo
Copy link
Contributor

rchiodo commented Dec 5, 2019

Not sure. Although I think we should move to a new issue (as your problem doesn't seem related to the one this issue is about). I'll create one:
https://github.com/microsoft/vscode-python/issues/8923

@ARF1
Copy link

ARF1 commented Dec 6, 2019

@rchiodo This comment really belongs to #3119 which unfortunately has been erroneously marked as duplicate of this issue and locked for comments.

The workaround for the problem that I had found for this issue now no longer works:

image

There is now absolutely no way left to work with IPython commands from vscode.

Would it be possible to reverse whatever "broke" the workaround until this issue will be solved more permanently?

@rchiodo
Copy link
Contributor

rchiodo commented Dec 6, 2019

Would it be possible to reverse whatever "broke" the workaround until this issue will be solved more permanently?

Sure but we'd have to know what caused it. I would hazard a guess that jupyter 'fixed' something and now we're not getting the output we expect.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 6, 2019

Looking through the IPython code, it looks like there's another message that Jupyter is sending us for some of these things.

We need to listen for IExecuteReplyMsg responses. One of these will have the pager results:
https://github.com/jupyterlab/jupyterlab/blob/9c25950fca4c443b709c572bf0f2e9fc8404251c/packages/services/src/kernel/messages.ts#L1050

Not sure how we interpret the page of data, but this would at least get the prun magic to work I believe.

Jupyter opens page results in a separate tab at the bottom.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 6, 2019

Moving back to triage. This seems like a hole in our implementation that we should fill in sooner rather than later.

@aragong
Copy link

aragong commented Dec 6, 2019

In that way to conclude that is nothing to do with my environment (in conda and in the vscode), I will try:
1- do the same with a new empty python3 environment.
2- How can I restore vscode to defaults settings (without delete extensions? is it possible?)

@rchiodo
Copy link
Contributor

rchiodo commented Dec 6, 2019

@aragong can you reply in issue #2603 instead for your problem? Your %%time issue is not related to the root cause of the other magics failing.

@rchiodo rchiodo self-assigned this Feb 10, 2020
@IanMatthewHuff IanMatthewHuff self-assigned this Feb 14, 2020
@IanMatthewHuff
Copy link
Member

Validated (mostly). I checked the ones listed in this thread and a sampling of other magics. These all worked:
len?
%time print('bar')
%%time
%prun print('Hello')
%alias
%conda list
%%HTML
%page
%pdoc

I did hit one that worked on jupyter and not here:
%lsmagic

But I think we can look for a customer upvote or request for that.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 22, 2020
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@Alonoparag
Copy link

%lsmagic doesn't work for me, using 1.51.4 OSS version on Manjaro Gnome 20

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants