7

When I try to run the debugger:

C:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara> cmd /C "C:/Users/Philip/miniconda3/envs/capra/python.exe c:\Users\Philip\.vscode\extensions\ms-python.python-2020.8.101144\pythonFiles\lib\python\debugpy\launcher 53607 -- c:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara\updater.py "
C:\Users\Philip\miniconda3\envs\capra\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init

I've worked out that if I install numpy into my base environment then I can get around the error. The question is how to activate the capra environment for the debugger?

I've tried following the guidance from VS Code:

1. pythonPath property of the selected debug configuration in launch.json

My launch.json file:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "pythonPath": "C:/Users/Philip/miniconda3/envs/capra/python.exe"
        }
    ]
}

Next:

2. python.pythonPath setting in the workspace settings.json

I restart VS Code and get:

We removed the "python.pythonPath" setting from your settings.json file as the setting is no longer used by the Python extension. You can get the path of your selected interpreter in the Python output channel. [Learn more](https://aka.ms/AA7jfor).

Lastly:

3. python.pythonPath setting in the user settings.json

My user settings file:

{
    "terminal.integrated.shell.windows": "C:/WINDOWS/System32/cmd.exe",
    "kite.showWelcomeNotificationOnStartup": false,
    "python.venvPath": "C:/Users/Philip/miniconda3/envs/capra",
    "python.pythonPath": "C:/Users/Philip/miniconda3/envs/capra/python.exe",
    "terminal.integrated.automationShell.windows": "C:/WINDOWS/System32/cmd.exe",
    "python.autoComplete.extraPaths": [
    
    ]
}

Still get the same numpy error.

Worth mentioning that I get exactly the same error when I look at the Python Test Log output after trying to discover tests.

2
  • Have you tried to use 'conda activate capra' in terminal? When we create and select a coda environment, VSCode will first enter the base environment, and after using this sentence to activate it, it will enter the newly created 'capra' environment. (You could also use" 'ctrl+shift+` " to open a new terminal, it will automatically activate.') Reference: conda.io/projects/conda/en/latest/user-guide/tasks/…
    – Jill Cheng
    Commented Aug 17, 2020 at 2:32
  • Yep. Running the debugger seems to reset this. See first code block for the message I get. It looks like the terminal isn't in any environment. However, as I mention if I install numpy in my base environment then the error goes away...
    – Jossy
    Commented Aug 17, 2020 at 7:26

4 Answers 4

6

You click on the Python 3.6 ..... bottom right side as shown in the picture below Click on red square part Python 3.6. ....

Then you just have to select the environments you have already created as shown in the picture below Select the environment in red circle

Then you run the code and code will run in the selected environment.

2
  • I have selected the capra environment. Using the debugger seems to kick me out of it and into base
    – Jossy
    Commented Aug 18, 2020 at 8:27
  • 1
    Debugger will kick you into base only when using VS Code terminal and with command conda activate capra ..... Use the above method I mentioned it will never kick you out of environment. I have confirmed it and I had same problem but after so many searches the above method I have shown is working fine
    – Imran
    Commented Aug 18, 2020 at 13:41
1

According to your description, you could try the following steps to use conda environment: (Example: Use python3.8 to create a conda environment named 'capra'.)

  1. Create a conda environment.

conda create -n capra python=3.8

After the creation is complete, reload VSCode, refresh and load several times.

  1. Select conda environment.

    click the lower left corner of VSCode to select the environment just created. enter image description here

  2. Activate the conda environment. You could use shortcut keys directly: Ctrl+Shift+`

    enter image description here

When debugging the code, the terminal shows that it is in the created environment:

enter image description here

  1. Install the required modules in the current conda environment.

In addition, for the'removed "python.pythonPath" setting' you mentioned, the reason is that you set the'workspace settings.json'. Now the python extension does not use the'pythonPath' here. When we set both in the two setting files, it will be removed. This will not affect the use of conda environment.

3
  • Why do I need to create a new environment? As per the question I'm looking to ensure that the debugger runs using the capra environment?
    – Jossy
    Commented Aug 18, 2020 at 8:28
  • @Jossy Yes, you can use the capra environment you created and then activate it. You could refer to it from the second step. The complete steps are provided for your reference.
    – Jill Cheng
    Commented Aug 18, 2020 at 8:54
  • @Jossy To better explain this process, I edited the above content.
    – Jill Cheng
    Commented Aug 18, 2020 at 9:22
0

In my case, Visual Studio Code version:1.70.2, the Python environment selection was on the bottom right. I clicked there and changed the environment to the conda location. To find your conda environment and respective python version, issue the commands: pip --version and python --version. Where to click in VisualStudioCode

0

My python selection is on the bottom right. It is set to my desired environment.

However, the debugger launches in the base environment.

I have added the following to launch.json

"python":"/Users/XXX/opt/anaconda3/envs/MY-ENV/bin/python"

What I find now is that it's using the python interpreter at that path, but the environment is still the base.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.