1

For some reason the jupyter notebooks on my VM are in the wrong environment (ie stuck in (base)). Furthermore, I can change the environment in the terminal but not in the notebook. Here is what happens when I attempt !conda activate desired_env in the notebook:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


# conda environments:
#
base                  *  /anaconda
azureml_py36             /anaconda/envs/azureml_py36
azureml_py38             /anaconda/envs/azureml_py38
azureml_py38_pytorch     /anaconda/envs/azureml_py38_pytorch
azureml_py38_tensorflow     /anaconda/envs/azureml_py38_tensorflow

I tried the answers here (e.g., first running !source /anaconda/etc/profile.d/conda.sh).

I also tried activating the environment using source rather than 'conda activate': !source /anaconda/envs/desired_env/bin/activate. This runs but doesn't actually do anything when I see the current environment in conda env list

Edit: also adding that if I install a package in the (base) environment in the terminal, I still don't have access to it in jupyter notebook.

Brian Barry
  • 439
  • 2
  • 17

1 Answers1

6

I'm the PM that released AzureML Notebooks, you can't activate a Conda env from a cell, you have to create a new kernel will the Conda Env. Here are the instructions: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-access-terminal#add-new-kernels

abeomor
  • 141
  • 3
  • To use the `azureml_py38` environment I skipped steps 1-2. I then created a kernel as in step 3. Is there another step I'm supposed to follow next? I opened a jupyter notebook following this step, and it's still in the `(base)` environment. – Brian Barry Nov 11 '21 at 18:01
  • The azureml_py38 is a default kernel. Just use the Kernel Python 3.8 – abeomor Nov 12 '21 at 19:08
  • that's the step I'm stuck at. I don't know how to "just use" a kernel. As mentioned, when I launch a notebook it's still in the base environment. – Brian Barry Nov 12 '21 at 19:26
  • 1
    So the part that I was stuck at - which for some reason isn't explained anywhere on the page linked - is that there is a drop down menu in the jupyter notebook to select the kernel. Just because a feature is in plain sight doesn't mean that its relationship to a problem is obvious. – Brian Barry Nov 30 '21 at 18:38
  • Should a kernel change using the dropdown menu result in a reflection of this when calling `!conda env list`? Because it always shows that (base) is activated in my case no matter what I choose in the dropdown menu... – Jaykob Feb 08 '22 at 09:43
  • No. Follow these instructions to explicitly add a kernel, it will not follow what is on your conda env list. Here are the instructions: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-access-terminal#add-new-kernels – abeomor Feb 09 '22 at 18:51
  • I added a kernel following the instructions and I'm able to select it in the dropdown list for the notebook. However the change seems not to be reflected in the notebook. My current workaround is to call things like this: `!source activate myenv && python ...`. But it's really annoying. – Jaykob Apr 12 '22 at 12:42
  • Hi @abeomor my AzureML notebook can't find either pip or conda on a newly created notebook. Any help? – Mauricio Maroto Apr 12 '22 at 15:20