Shift + enter does not execute code in .py in created console

OS: mac sequoia 15.1.1
Python 3.13.1
JupyterLab 4.3.5

First of all, this is NOT about running cell by cell in a jupyter notebook file. But creating a console for a file editor and execute selected code in .py file. to the console instead. shift + enter (which is Jupyter default shortcut) has always been working for me in early version of JupyterLab on windows machines in the past.

I have searched the internet extensively and found only a couple of places talking about this particular issue and some proposed add a keymap as potential work arounds But I could not make it work out on my mac on sequoia 15.1.

A couple of days ago, I installed python 3.13 and jupterlab 4.2 on my mac with sequoia 15.1 and found shift + enter does not work as expected.

Here is my work flow:

  1. launch JupyterLab in my virtual evnironment

  2. open a .py file with only two lines of sample code below

    import geojson
    geojson?

  3. right click file editor pane and select ‘create console for editor’ to open a console associated with this .py file

  4. in file editor click anywhere (beginning, middle or end) in first line of code ‘import geojson’

  5. press shift + enter does nothing. surprise.

  6. click top menu “Run”, select “Run Selected Code” will execute ‘import geojson’ regarding where the cursor is. However, the cursor disappeared in file explorer after the execution. It did not move to the beginning of next line automatcially

  7. then I had to click/select second line of code ‘geojson?’

    if I click anywhere but the very beginning of the second line
    neither shift + enter short cut nor run selected code from menu bar did anything.

However, if I click and keep cursor at the very beginning of line,
while shift + enter still does nothing
run select from top menu executed the line of code.

In summry,

  1. in JupyterLab 4.3, shift + enter does not work for excecuting code from file editor to created console

  2. run select only works when the cursor is at the very beginning for the following lines to execute. it works for the first line of code wherever the cursore is.

  3. Add keyboard shortcut manually does not work. Sometimes, added script in ‘user preference’ setting just disappeared . Yes, i did press command + S to save my setting changes.

This is very different experience from what I have ever done.

Somone online suggested to add ‘shift + enter’ explicitly into keyboard mapping.
I added the following lines in setting → keyboard shortcut → user preference

"shortcuts": [
    {
        "args": {},
        "command": "fileeditor:run-code",
        "keys": ["Shift Enter"],
        "selector": ".jp-FileEditor"
    }
]

Then I relaunch the kernel. But shift + enter still does not work. Not sure if I did anything wrong with the script above.

Wonder if anyone has same issue in JupyterLab 4.3 and what are possible work arounds. Use top menu Run is less ideal for me because keep switching between keyboard and mouse just execute code is very cumbersome.

I am almost sure this is not a mac vs. windows thing.
And I did not know from which version of Jupyter ‘shift + enter’ stop working in my usual workflow.

Greatly appreciate your input !

Well, after more research. I concluded shift + enter does not work properly in 4.x for my use case. So, I just downgraded to Jupyter 3.x and it works again. Not ideal. But wait for developers to fix the issue eventually.

My code consoles execute with Shift+Enter.

Check that Settings → Code Console → Interaction mode is set to notebook.

Edit: I just noticed you wanted Shift+Enter in the Editor, nevermind then. Indicated Hotkey Shift+Enter does not work for me neither.

1 Like

Weirdly enough the problem seems to be Shift Enter not getting through.
If you use Ctrl Enter it works.

{"shortcuts": 
    [
        {
            "args": {},
            "command": "fileeditor:run-code",
            "keys": [
                "Ctrl Enter"
            ],
            "selector": ".jp-FileEditor"
        }
    ]
}

Edit: Also tracked here: send to console does not work · Issue #16272 · jupyterlab/jupyterlab · GitHub

1 Like