0

I am trying to run a Python file in debug mode, and I get an error because the Powershell integrated terminal it starts is bare. To get it to work, I want it to use the following profile which initializes the Anaconda env first.

    "terminal.integrated.profiles.windows": {
        "PowerShell -conda": {
            "source": "PowerShell",
            "args": ["-ExecutionPolicy", "ByPass", "-NoExit", "-Command", "& 'C:/Users/Marko/anaconda3/shell/condabin/conda-hook.ps1' ; conda activate 'C:/Users/Marko/anaconda3'"]
            }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell -conda"

What should I do to make that happen?

1
  • For now, a workaround is to run C:/Users/Marko/anaconda3/shell/condabin/conda-hook.ps1 and then conda activate 'C:/Users/Marko/anaconda3' by hand in the debug terminal. Commented May 26, 2021 at 8:32

2 Answers 2

1

You need to init conda first.

Run conda init command in any terminal.

It will create a profile.ps1 file under the folder of C:\Users{UserName}\Documents\WindowsPowerShell.

After that, if you open the PowerShell, conda will work. It equals to C:/Users/Marko/anaconda3/shell/condabin/conda-hook.ps1

Sign up to request clarification or add additional context in comments.

1 Comment

After running conda init everything works automatically and I do not need the profile setting in my original post. I don't even need to activate the Python env or add stuff to PATH. The solution is as good as I could imagine it to be.
0

If you want conda environment is activated every time opening an new integrated Terminal, after selecting conda environment as interpreter, what you need to do is pressing Ctrl+Shift+` to open a Terminal

  1. run conda activate <envname>

  2. In Settings.json, set "python.terminal.activateEnvironment": true

Then no matter run or debug code, Terminal is always activated automatically:

enter image description here

2 Comments

When I turn on that option what happens is that conda activate base gets run in the terminal. The problem is that it does not run the C:/Users/Marko/anaconda3/shell/condabin/conda-hook.ps1 and I get an error that it cannot find conda. That is why I keep that option turned off and have my own terminal profile.
Seems you didn't add Anaconda to PATH, so there's error showing can't find conda. Try to add \installation path\Anaconda and \installation path\Anaconda\Scripts to PATH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.