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

Activating a conda environment using conda instead of source #1882

Closed
eyadsibai opened this issue Jun 6, 2018 · 36 comments · Fixed by #2717
Closed

Activating a conda environment using conda instead of source #1882

eyadsibai opened this issue Jun 6, 2018 · 36 comments · Fixed by #2717
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority linux macos

Comments

@eyadsibai
Copy link

Environment data

  • VS Code version: 1.23.1
  • Extension version (available under the Extensions sidebar): 2018.5.0
  • OS and version: Linux Manjaro 4.16.13-1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.3 / conda version: 4.5.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda

Actual behavior

I am using the zsh shell. When I create a new python terminal it uses source activate 'name_of_environment'

Expected behavior

I am using the zsh shell. When I create a new python terminal it uses conda activate 'name_of_environment

Steps to reproduce:

  1. install latest conda
  2. add ". /etc/profile.d/conda.sh" to your .zshrc file as recommended by any conda version after 4.4
  3. try to create a new python terminal within vscode whille the activateEnviroment setting is true
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug needs PR area-terminal labels Jun 6, 2018
@DonJayamanne
Copy link

DonJayamanne commented Jun 6, 2018

@brettcannon brettcannon added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Jun 6, 2018
@brettcannon
Copy link
Member

Re-classifying as an enhancement since the old ways still work, they have simply introduced a new way of doing this.

@eyadsibai
Copy link
Author

eyadsibai commented Jun 6, 2018

the old way doesn't work for me. If I am following the new way of adding the conda to the environment, the old way doesn't work anymore.

I am getting an error:
source: no such file or directory: activate

@brettcannon
Copy link
Member

Anaconda's shell scripts that they have you source as part of the new approach must be clobbering something then.

The problem is that we can't leave old users behind and blindly cut over to this new approach, so if we're going to support both we are going to have to add detection code for what version of Anaconda someone is using which complicates things.

@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug needs verification and removed needs PR feature-request Request for new features or functionality labels Jun 7, 2018
@brettcannon
Copy link
Member

@eyadsibai BTW, if you need to shut off our automatic activation then see https://code.visualstudio.com/docs/python/environments#_activate-an-environment-in-the-terminal for the python.terminal.activateEnvironment.

@brettcannon
Copy link
Member

Another snafu in all of this is that this new approach is only documented for UNIX-based operating systems and not for Windows at all.

@eyadsibai
Copy link
Author

eyadsibai commented Jun 12, 2018

@brettcannon thanks, but I like that feature 😅 , I hope it can be resolved soon.
Why dont u assume one approach and if you get an error you try the other one. Similar when trying to install a package using conda. you try to source the environment if it doesn't work you try to install the package thru the conda command without sourcing the environment. Similar approach can be done here.

@brettcannon
Copy link
Member

@eyadsibai it's not that simple because we don't have that kind of access to the terminal, i.e. we just get to send in text to execute and that's pretty much it. So we will have to do detection on the TypeScript side of things to figure out the right approach.

Could you do us a favour and let us know if executing that shell script multiple times causes an issue? E.g. if we blindly executed it and then the conda activate command would it work as appropriate?

@brettcannon
Copy link
Member

brettcannon commented Jun 12, 2018

It looks like this approach is entirely for UNIX only; Windows is still only for Command Prompt and still through the activate.bat script (at least to activate the base environment, and then conda activate is available).

@brettcannon
Copy link
Member

And final comment: conda has not updated their docs on activating an environment yet.

@ericsnowcurrently
Copy link
Member

@brettcannon, is there anything left to "verify" here?

@brettcannon
Copy link
Member

@ericsnowcurrently yep, it was to verify that if you follow conda's current documentation does it break our approach to conda environment activation (i.e. does adding the recommended stuff to your shell break us).

@d3r3kk
Copy link

d3r3kk commented Aug 2, 2018

Adding the recommended stuff to your shell does not break us, but it doesn't always work, either. See issue #2315 and #2266 for further efforts being put toward this issue.

Closing this issue as it is covered by others.

@d3r3kk d3r3kk closed this as completed Aug 2, 2018
@DonJayamanne
Copy link

DonJayamanne commented Aug 2, 2018

@d3r3kk

I'd close #2315 and keep this open, as this has the original issue and the solution. (I.e. mentioned the new way of activation). #2315 merely mentioned another symptom.

@DonJayamanne DonJayamanne reopened this Aug 2, 2018
@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Oct 1, 2018

BTW, I tried out miniconda 4.4.0+ on Windows and it worked fine. So we don't need to change anything there.

@DonJayamanne
Copy link

I'm assuming this is with mini-conda not being in path.

@ericsnowcurrently
Copy link
Member

correct

@DonJayamanne
Copy link

I'm creating an issue for Windows + Conda

@DonJayamanne
Copy link

@ericsnowcurrently
This has never worked for @jmew, and that's why we pulled this issue into this sprint.
I've created an issue to resolve/track this #2753

@DonJayamanne
Copy link

Fails on a Mac

@DonJayamanne
Copy link

DonJayamanne commented Oct 3, 2018

I modified the code, and found that it still fails.
When attempting to activate in 4.5.11, i get the following message:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /Users/donjayamanne/anaconda3/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s /Users/donjayamanne/anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bash_profile

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like

    export PATH="/Users/donjayamanne/anaconda3/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

Next, I re-enabled the above in my bash_profile.
And it still fails.

I.e. for 4.4.0, I think we should NOT use the fully qualified path, we have to get the user to add the necessary startup script into their bash_profile.
I'd expect the same to be on linux as well.

@ericsnowcurrently
Please could you confirm, the behavior on Linux (I'm assuming that's where you're testing this).

@brettcannon /cc

We might have to review the solution for Mac & Linux.
Windows has been (is being) sorted in a separate issue.

@ericsnowcurrently
Copy link
Member

We are going to try going back to source activate but with an absolute path to the "activate" script based on the path to conda.

@mdivk
Copy link

mdivk commented Oct 10, 2018

cat /opt/cloudera/parcels/Anaconda/etc/profile.d/conda.sh

_CONDA_EXE="/home/jhelmus/workspace/misc/cdh_parcel/anaconda/scripts/parcel/tmp/Anaconda-5.1.0/bin/conda"
_CONDA_ROOT="/home/jhelmus/workspace/misc/cdh_parcel/anaconda/scripts/parcel/tmp/Anaconda-5.1.0"
_conda_set_vars() {

Should Helmus folder be created for everyone using Anaconda? I am very curious on this.

@mdivk
Copy link

mdivk commented Oct 10, 2018

I am not able to activate the new env. I am using conda 4.4.10

I am using command: conda activate
Error:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

$ echo ". /opt/cloudera/parcels/Anaconda/etc/profile.d/conda.sh" >> ~/.bashrc

or, for all users, enable conda with

$ sudo ln -s /opt/cloudera/parcels/Anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH. To do so, run

$ conda activate

in your terminal, or to put the base environment on PATH permanently, run

$ echo "conda activate" >> ~/.bashrc

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file. You should manually remove the line that looks like

export PATH="/opt/cloudera/parcels/Anaconda/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^

[hadoopuser@hadoop02 bin]$ conda activate py36

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

$ echo ". /opt/cloudera/parcels/Anaconda/etc/profile.d/conda.sh" >> ~/.bashrc

or, for all users, enable conda with

$ sudo ln -s /opt/cloudera/parcels/Anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH. To do so, run

$ conda activate

in your terminal, or to put the base environment on PATH permanently, run

$ echo "conda activate" >> ~/.bashrc

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file. You should manually remove the line that looks like

export PATH="/opt/cloudera/parcels/Anaconda/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^

If I followed the instruction in the above error output, I got new error prompted in the output below:

-bash: /home/jhelmus/workspace/misc/cdh_parcel/anaconda/scripts/parcel/tmp/Anaconda-5.1.0/bin/conda: No such file or directory

So what it the secret command to activate an environment? My Anaconda is 4.4.Thank you very much.

@DonJayamanne
Copy link

If I followed the instruction in the above error output, I got new error prompted in the output below:
-bash: /home/jhelmus/workspace/misc/cdh_parcel/anaconda/scripts/parcel/tmp/Anaconda-5.1.0/bin/conda: No such file or directory

So what it the secret command to activate an environment?

Please file your issue against conda, they'll be able to assist you with your issue.

@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 10, 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 linux macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants