Skip to content
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

Be able to activate conda environments when conda is not on PATH #2266

Closed
DonJayamanne opened this issue Jul 27, 2018 · 10 comments
Closed

Be able to activate conda environments when conda is not on PATH #2266

DonJayamanne opened this issue Jul 27, 2018 · 10 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority windows

Comments

@DonJayamanne
Copy link

Unable to activate conda environment created on Windows in PS.
Nothing happens when we create a new python terminal.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug needs PR area-terminal windows labels Jul 27, 2018
@DonJayamanne DonJayamanne added this to the Aug 2018 milestone Jul 30, 2018
@DonJayamanne
Copy link
Author

DonJayamanne commented Jul 30, 2018

I can replicate this.
We need to change the way conda environments are activated.
The problem is conda is not in the current path.

We'll need to identify path to related conda and use the command conda activate <envname>.

@DonJayamanne DonJayamanne added important Issue identified as high-priority and removed P0 labels Jul 30, 2018
@DonJayamanne
Copy link
Author

@brettcannon
Please feel free to change priority and Milesone (this was identified @ EuroPython).

@brettcannon brettcannon changed the title Unable to activate conda environment Be able to activate conda environments when conda is not on PATH Jul 30, 2018
@DonJayamanne
Copy link
Author

DonJayamanne commented Aug 2, 2018

@brettcannon @Microsoft/pvsc-team
Lets discuss over Teams or similar (too complicated to do over GitHub messages).

Here's what i found (researched on Windows and Mac):

Conda no in path:

  • We cannot use <full path to conda exe> activate <env-name>
  • When you do this, you get an error from conda indicating the fact that the shell has not been initialized for conda.
  • The requirement is to run the conda shell activate scripts

Solution:

  • We need to run two commands now:
    conda activation script && conda activate <env-name>

What is the activation script for conda?

  • On mac for Ananconda the activation script is /Users/donjayamanne/anaconda3/bin/activate
    On Mac, the above script is in the bash_profile.
  • On windows, its some batch file (can't remember).
    On Windows, one needs to launch the Anaconda Prompt (command prompt with the necessary startup script - does not work on Powershell).
  • In both Windows and Mac, the conda activation script, is located where ever base root or Conda is installed.
  • E.g. if you install Anaconda using pyenv, then the activation script is located here:
    /Users/donjayamanne/.pyenv/versions/anaconda3-4.4.0/bin/activte

Discussion

  • Do we need to support the old ways of activating conda environments (for users with older versions of conda)? I think yes, else all of a sudden things just stop working for people.
  • The biggest challenge will be in identifying the root conda environments.

@DonJayamanne
Copy link
Author

Do we need to support the old ways of activating conda environments (for users with older versions of conda)? I think yes, else all of a sudden things just stop working for people.

@qubitron said yes.

@brettcannon
Copy link
Member

Can we detect when someone has already activated their shell? If so then we can do the conda activation script command for them as necessary, but if we can't detect it then we should make sure it's idempotent, else we will need to not do it so as to not mess up people who have set it up already.

@DonJayamanne
Copy link
Author

then we should make sure it's idempotent

Yes it is

@brettcannon
Copy link
Member

@DonJayamanne Great! Then I guess that leaves how we detect what version of conda was used to create an environment/whether it activates the new way or the old way.

@GollyJer
Copy link

@brettcannon Thanks for your feedback on
#2417 (comment)
and linking it to this related issue.

I think these issues are similar but different. I've updated the question to be more specific.
https://stackoverflow.com/q/51935526/25197
It's really about the display of the active environment in addition to the interpreter.

In relation to this github issue...
Another thing you guys might want to look at is the use of environment.yml files in the project root.
We use them to define the conda environment for our repos.

They look like this.
image

You could theoretically detect the correct environment from the file name: property.

@brettcannon
Copy link
Member

@GollyJer interesting idea about detecting the name from the environment.yml! And I replied on SO about your more specific question (summary: already fixed 😄 ).

@ericsnowcurrently ericsnowcurrently self-assigned this Aug 27, 2018
ericsnowcurrently added a commit that referenced this issue Aug 27, 2018
Also, favor Python 3 over Python 2 when falling back to system Python.
@brettcannon brettcannon marked this as a duplicate of #1944 Sep 5, 2018
@brettcannon brettcannon reopened this Sep 19, 2018
@brettcannon brettcannon removed this from the Aug 2018 milestone Sep 19, 2018
@ericsnowcurrently
Copy link
Member

The $PATH part of this is resolved with #1944. The conda activate part will be resolved with #1882.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority windows
Projects
None yet
Development

No branches or pull requests

4 participants