pythonvisual-studio-codecoderunner

How to change the default executor of Python in VSCode Code Runner? The `executorMap` does not work


Is it possible to change the default command executed by the play button for Python files? Instead of running conda run ..., I'd like it to directly use <path-to-current-env>\python.exe ... (as shown in the second image of this post).

Background

According to the official documentation from VS Code,

enter image description here

When you click the Run button, it should directly use the python.exe from the corresponding virtual environment to execute the code. That’s how it used to work on my computer as well.

However, today I noticed that the default command in Code Runner (by clicking the Run button) has changed to:

enter image description here

I copied the text from this image below:

I have Miniforge installed, and its conda/mamba commands usually only work properly in their own dedicated terminal window. Unless I set the default terminal to Miniforge's exclusive one, this Run button is basically useless. Even when it does work, I really dislike using conda run - I much prefer switching to the virtual environment first and then directly running python <path>.py, or alternatively executing the python.exe file from the virtual environment like I used to do.

This error appears only because the default PowerShell terminal in VS Code cannot execute Conda/Mamba commands properly. If I change the default terminal in VS Code to the Miniforge Prompt, it works correctly. The command conda run ... no longer leaves this output in the terminal, so I don’t have an image or text to share here.

I also tried modifying the executorMap setting for Python, but even after I changed it, clicking the play button still executed the conda run ... command. This makes me suspect the issue isn’t related to Code Runner, though the play button’s behavior is tied to that plugin.

Does anyone know how to adjust this? I can't seem to find any relevant settings in the Code Runner plugin's configuration to tweak this behavior.


My question appears very similar to How do you change your default Code Runner execution command in VS Code?, however, while their issue was resolved by modifying the executorMap setting, this solution didn't work in my case. It seems Code Runner's behavior is being overridden by Miniforge?


Solution

  • Thank you all in the comments for your help. The issue actually stemmed from my misunderstanding of VS Code's play button, and I apologize for the confusion and trouble this may have caused.

    The "Run Python File" option in this button is not part of the Code Runner extension—it’s a feature of the VS Code Python-related extension. This problem and similar issues have already been reported on GitHub:

    Thanks to the second link above, I have found a way to solve this problem. Simply disable the "Python Environments" extension. Here’s how:

    With the "Python Environments" extension enabled (when enabled, the button on the extension page shows "Disable"):
    Enabled

    Result1

    Next, click the "Disable" button to disable the "Python Environments" extension (when disabled, the button shows "Enable". You might need to restart VS Code.):

    Disabled

    Result2