1

I am new to VSC and have some experience in Anaconda. Recently, I started learning VSC and found an interesting case. Method 1: When I start VSC from Windows CMD prompt and run any Conda command (i.e. conda list) it throws a big error. I tried to solve it by following many Google answers without success. Method 2: Then I thought of launching VSC from Anaconda Prompt and all conda commands are working. Could you please explain what is the difference b/w these 2 methods and why doesn't my method 1 work fine?

Method 1 with Windows CMD with Fail

Method 2 with Anaconda Prompt

deepeshsingh
  • 21
  • 1
  • 3

3 Answers3

6

Conda has its own environment path where all its dependencies installed in it including python.

So if you launch vs code from conda navigator, vs code will run conda's python path, but if you launch vs code from your desktop it will use the path of python installed in your AppData/temp folder.

You can still launch conda's python path from vs code by:

  • Click on View > Command Palette > Python: Select Interpreter and click python conda's path

Else to successfully run Conda Shell or Conda PowerShell command you should use Anaconda Prompt for Shell and Anaconda PowerShell Prompt for PowerShell.

For your actual case you have to launch Anaconda PowerShell Prompt and type the same command you showed which is conda info --envs or conda info -e are the same.

Official conda commands How-To

VS Code Official How-To

  • Hey, thanks for your comments. Not sure, if my doubt was clear above. I am able to compile Python queries in both ways, but the Method -1 (launching through Win CMD, not able to run "Conda" commands like conda info --envs.. – deepeshsingh Oct 02 '20 at 14:36
  • To successfully run Shell or PowerShell command you should use **Anaconda Prompt** or **Anaconda PowerShell Prompt** –  Oct 02 '20 at 15:16
3

You can add a Conda (e.g. Powershell) terminal profile to VSCode by editing the settings JSON.

You can figure out the conda shell details from the shortcut that conda itself installs in your start menu: C:\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\Anaconda Powershell Prompt (miniconda3)

This is for instance what I have been successful with: (Adds a "Conda Powershell" terminal option)

    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "Conda Poweshell": {
            "path": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
            "args": [
                "-ExecutionPolicy",
                "ByPass",
                "-NoExit",
                "-Command",
                "& 'C:\\Users\\<user>\\miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Users\\<user>\\miniconda3' "
            ],
            "icon": "terminal-powershell"
        }
    },
Roy Shilkrot
  • 3,079
  • 29
  • 25
1

From the answer posted at Error when trying to use conda on vs code: conda : The term 'conda' is not recognized as the name of a cmdlet

To get python, anaconda, and conda to work well with VS Code I installed the Python extension.

Then in the Python extension settings, set the Python: Conda Path to your conda.exe and the 'Python: Default Interpreter Pathto yourpython.exe`.

For me the conda.exe path was in ...\Anaconda3\Library\Scripts\conda.exe and the 'python.exewas the conda base env one at...\Anaconda3\python.exe`

user3731622
  • 4,844
  • 8
  • 45
  • 84