Search code examples
pythonvisual-studio-codeanacondacondavscode-code-runner

Miniconda VS Code Output Not Running From Code Runner Output Tab


I am an absolute beginner using Python and have been trying to use Miniconda environments. I created a couple of environments and tried to use them with VS Code. Here is my workflow:

  1. Open command prompt > activate my desired environment.
  2. Open VS Code > Select my desired environment on the Command Palette.
  3. Run Code.

This is what my VS Code terminal shows: enter image description here

My issue is that I have been getting mixed results. Sometimes my code runs on the terminal, but I expected the output to show on Code Runner's Output tab. Sometimes the Output tab shows an error importing packages that are explicitly downloaded on my environment. Am I using the correct workflow with these two tools?


Solution

  • It seems you are using both Code Runner and Python extensions. It is not recommended to use the Code Runner extension without special requirements. Please use the official extension Python to execute the code.

    enter image description here

    Explanation:

    • Code Runner will display the result in the OUTPUT panel by default, and the Python extension will display the result in the integrated terminal

    • The interpreter you choose for the current workspace (shown in the lower right corner) only applies to the Python extension, because that's what it does. Select Interpreter function has no effect on Code Runner.

    • If you use Code Runner, it uses the python -u path\to\name.py command to execute the script, then python will be the python interpreter configured by the environment variable path in your machine, not necessarily the one you choose in vscode.

    Other information:

    If you need Code Runner to output in the terminal, you can add the following settings.

        "code-runner.runInTerminal": true,
    

    The name of the terminal tab is code, which is the green box in the picture. The red box is the terminal executed by the Python extension.

    enter image description here

    Useful links: