[Python] Shift+Enter in VS Code Python does not run selected lines

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm following this tutorial on how to run selected lines in VS Code Python. I highlighted the following code:

    x = [1,2,3,4,5]
    x[2:3]


    and pressed Shift+Enter, but the code is just shown in the Python terminal instead of executing and returning the result.

    Here is what happens in my terminal:

    (base) PS D:\stock> C:/Users/shadowpioneer/anaconda3/Scripts/activate
    (base) PS D:\stock> conda activate base
    (base) PS D:\stock> & C:/Users/shadowpioneer/anaconda3/python.exe
    Python 3.13.5 | packaged by Anaconda, Inc. | ...
    >>>


    Then when I press Shift+Enter again, the code is simply repeated:

    >>> x = [1,2,3,4,5]
    ... x[2:3]
    ...


    It seems like VS Code is just sending the code to the Python REPL but not executing it.


    1. I have installed the Python extension and Jupyter extension in VS Code.


    2. I have selected the correct Anaconda Python interpreter.


    3. I am using a .py file (not a notebook).

    How can I configure VS Code so that Shift+Enter executes selected Python code and shows the output?

    Continue reading...

Compartilhe esta Página