Search code examples
pythonpython-3.xvisual-studio-codeminicondavscode-code-runner

How to fix Code Runner plugin in VS Code for Miniconda using?


Recently I decide to install Miniconda on my MacBook.

The first problem I faced with was "(base) environment" that Miniconda activated each time as I opened a terminal. So, I disabled this option by command:

conda config --set auto_activate_base false

by this advice: How do I prevent Conda from activating the base environment by default?

But I faced with another problem. Usually, I use a Code Runner plugin for VS Code which allows to run code by ctrl+alt+N hot keys. But after "auto_activate_base" configuration I am getting an error.

I suppose the problem is with the Code Runner plugin that can't activate Python 3 interpreter anymore (by path: "~/miniconda3/bin/python"). Instead of this, it's using Python 2.7 (by path: "/usr/binpython") even when I'm choosing Python 3 interpreter.

# For example, if I wrote Python 2.7 code style via ctrl+alt+N I get a correct result
n = 1
print("The number is: %s" % n)

The number is: 1

# But, Python3 style code return an error
n = 1
print(f"The number is: {n}")

File "<path to file> print(f"The number is: {n}") ^ SyntaxError: invalid syntax

Earlier, when I used an Anaconda distribution the Code Runner plugin worked fine. How can I get similar behavior with Miniconda?


Solution

  • The problem was solved by setting code-runner.executorMap parameter which defines a path to Python-interpreter by default.

    Need to edit "setting.json" file in VS Code the next way:

    {
        "editor.fontSize": 14,
    
        "code-runner.executorMap": {
            "python": "~/miniconda3/bin/python"
        }
    
    }