Skip to content

Conda command broken for new anaconda python installations #5503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ARF1 opened this issue Apr 28, 2019 · 7 comments
Closed

Conda command broken for new anaconda python installations #5503

ARF1 opened this issue Apr 28, 2019 · 7 comments
Assignees

Comments

@ARF1
Copy link

ARF1 commented Apr 28, 2019

Issue Type: Bug

When the Anaconda / Miniconda python distribution is installed with an installer of the current version on Windows, the conda is no longer added to the PATH environment variable.

See: https://docs.anaconda.com/anaconda/reference/release-notes/#what-s-new-in-anaconda-4-4

The python extension however still calls the command conda (and presumably others) as if they were available in PATH.

PS Z:\testfolder> conda activate myenv
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try 
again.
At line:1 char:1
+ conda activate myenv
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Steps to reproduce:

  1. Run without debug any python file with an anaconda environment selected.

Extension version: 2019.4.11987
VS Code version: Code 1.33.1 (51b0b28134d51361cf996d2f0a1c698247aeabd8, 2019-04-11T08:27:14.102Z)
OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz (4 x 2295)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 7.88GB (3.18GB free)
Process Argv Z:\testfolder
Screen Reader no
VM 0%
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Apr 28, 2019
@ryan-feeley
Copy link

Try typing conda init from powershell. I believe that will add to or generate a powershell profile.ps1 file that will automatically add the requisite paths going forward.

You may first need to first navigate to /Anaconda3/Scripts/conda.exe.

I don't know if vscode or anaconda needs to fix this up, but I just went through this same pain.

@ryan-feeley
Copy link

ryan-feeley commented Apr 29, 2019

I don't know exactly what's going on with the details, but it looks like the Python extension has a setting "Python > Terminal: Activate Environment" that attempts to call conda to activate a given environment (base, myenv, etc).

However, this command won't execute properly unless your powershell startup script is already doing some work. Running conda init once will take care of setting this up, but by default it will activate the base environment any time you launch powershell (inside or outside of code). It looks like you can call conda deactivate to get a standard PS prompt. I suppose you could add that to your profile.ps1 script if you want to get a normal powershell prompt and to let vscode take care of activating your desired environment.

Looking at this thread, perhaps you could run

conda install powershell_shortcut to use the alternative way that does not require conda init.

@DonJayamanne DonJayamanne self-assigned this Apr 29, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 29, 2019
@DonJayamanne
Copy link

DonJayamanne commented Apr 30, 2019

@ARF1
Please add the path to Conda in you settings.json file as follows:

"python.condaPath": "<fully qualifieid path to conda executable>"

@ARF1
Also please could you let us know whether the suggestion from @ryan-feeley worked?

@DonJayamanne DonJayamanne mentioned this issue Apr 30, 2019
24 tasks
@DonJayamanne DonJayamanne added the info-needed Issue requires more information from poster label Apr 30, 2019
@ARF1
Copy link
Author

ARF1 commented May 1, 2019

@ryan-feeley You suggest running conda init from powershell. Will the file created be system-wide or vscode-specific?

I like that anaconda now refrains from cluttering my system-wide path & environment varible settings and I am somewhat reluctant to undo their good work. ;-)

Ideally I would like to limit the fix to the vscode-specific powershell.

@DonJayamanne
I tried your python.condaPath suggestion. Now vscode show an error box in the bottom right hand corner with the message:

Activation of the selected Python environment is not supported in PowerShell. Consider changing your shell to Command Prompt.

When clicking on the "More Info" button it links to #2898.

Also note: I do not quite understand why vscode finds all my conda environments without any problem but somehow fails to find the location of the conda command. This is surprising since it is just one level above the environments in the folder hierarchy.

@ARF1
Copy link
Author

ARF1 commented May 1, 2019

@DonJayamanne
I just realised I misunderstood the description of the python.condaPath setting. It says:

Path to the conda executable to use for activation (version 4.4+).

I took that to mean that the directory was required. What is actually required it the path plus the conda executable. I set Z:\Miniconda3\condabin\ required was Z:\Miniconda3\condabin\conda.bat.

Is the description misleading? It might just be me...

Anyway after fixing this, conda now works. - Sort of... It starts off with some error messages before then working ok:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.




PS Z:\myproj> Z:/Miniconda3/Scripts/activate
PS Z:\myproj> conda activate myenviron
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At line:1 char:1
+ conda activate myenviron
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS Z:\myproj> & Z:/Miniconda3/condabin/conda.bat install --name myenviron rope
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: Z:\Miniconda3\envs\myenviron

  added / updated specs:
    - rope

<... snipped ...>

Thus setting python.condaPath provides a workaround for #5533.

@ryan-feeley
Copy link

@ARF1

I hardly have even passing knowledge of how this works, but I think running conda init will have system-wide effects on your user profile. If you run it from cmd.exe, it will add stuff to your path in a temporary on-demand way by adding an AutoRun entry to HKCU\Software\Microsoft\Command Processor such that it runs conda_hook.bat when you launch cmd.exe (and perhaps other programs).

If you run conda init from powershell it will add some script code to $USERPROFILE/Documents/WindowsPowerShell/Profile.ps1 that does similar steps.

That said, this approach is a little cleaner than the older "Add a bunch of Anaconda directories to your system path" approach since with the newer method they are only messing with your path in a temporary way when you're in a terminal program. At the end of the day you want something on your path or you'll spend all your time typing out fully-qualified executable names.

@DonJayamanne
Copy link

Closing as we expect users to setup their shells for conda to work.
The extension will no longer attempt to resolve this on behalf of the user.

@ghost ghost removed info-needed Issue requires more information from poster triage labels May 16, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants