Creating environments in Anaconda Notebooks

I see that we can create custom environments on Anaconda Notebooks, but the docs on the topic explain everything with Anaconda Navigator, which I think applies to the Anaconda Distribution. Do I understand correctly that, to manage environments, we need to install the Anaconda Distribution locally, and then sign in with our Anaconda Nucleus account?

If so, it would be nice to explain this a little bit better in the documentation, because I’m a first time user to both Nucleus and Notebooks and this was not entirely clear to me.

Hi Juan,

You should not need to install the Anaconda Distribution locally. Instead, I would recommend following the instructions under Conda environments in the README.ipynb file in your Anaconda Notebook, specifically the sections Creating custom environments, Activating custom environments, and Installing packages. I’m pasting those sections below, too :slight_smile:

Creating custom environments

If you need a specific set of packages that are not included in one of our default environments, you can create your own.

WARNING Custom environments will use your personal storage space and can easily get quite large, so only include the packages you need

To create a new environment, open a new terminal from the Anaconda Notebooks home page. Then, run the command below. You can even use the same command to specify the version of a package to install within your new environment by adding the package and version number to the end of the command.

Only environments that have the notebook or ipykernel package installed can act as notebook kernels.

# Run this command to create a custom environment running Python 3.9
!conda create --name ENVIRONMENT_NAME python=3.9 ipykernel -y

It should take a minute or two for your environment to be created. Afterwards, the environment will appear in the Select Kernel modal (see Activating custom environments below) after roughly 30 seconds. You might need to close and reopen the README.ipynb or refresh the browser for the kernel to appear.

Activating custom environments

There are a couple ways to activate your environment:

  • Click the kernel at the top right of the notebook (“anaconda-.-py<PYTHON_VERSION>”), then switch to the kernel of the environment you created in the Select Kernel modal.
  • From the Launcher, select the notebook displaying your custom environment name.

Installing packages

You can then install any further packages you need by running the following:

!conda install PACKAGE_NAME -y

1 Like

Oh wow, I didn’t even see there was a README.md :slight_smile: Thanks a lot!

Following the !conda create --name ENVIRONMENT_NAME python=3.9 ipykernel -y immediately exhausted my free plan storage, so I stopped the process and ran a !conda clean -a -y.

By the way, wondering if %conda should be advised instead of !conda? I know it probably has no effect in Nucleus, but just so that people get used to the good practices.