Jupyter Notebooks come with pre-configured environments that include software commonly used for research analyses. However, these may not include all of the packages that are necessary for a given analysis. Conda is a package management system to find and install the packages you need.
Overview
Conda is a cross-platform package management system that works on Windows, MacOS, and Linux. Conda is used to install software packages and their dependencies. As a package manager, it can help you find and install packages.
By default, Jupyter Notebooks come with a pre-configured base environment that includes software most researchers will use for their analyses. However, sometimes you will need to add, remove, or update packages to better suit your needs. To do that, you will need to configure a new conda environment where you can fully customize the installed software.
How to install conda
You can install conda and keep it on a detachable persistent disk.
1. In your Jupyter Notebook, run the following code, substituting in a name for your new environment for name_of_new_environment
(this may take 2-4 minutes to complete)
conda create --clone base --prefix /home/jupyter/name_of_new_environment -y
Note: The -y is important. Since the output is non-interactive, this will respond “y” to any prompts. Without the flag, the notebook will hang, and you will need to restart the kernel.
2. To see the new environment, refresh the webpage
3. Verify that you're in the correct environment by going to the Kernel menu on the toolbar, choosing Change Kernel, and selecting Python[conda:env:name_of_new_environment]. For example, if you named your new environment newEnvironment, you would select Python[conda:env:newEnvironment].
Now you should see the name of your new kernel displayed at the top of the notebook:
4. Once you have selected your new kernel, use the following code to customize your environment by adding a package (substituting the name of the package you want to install for "package name"):
!conda install package name
You can also use conda to remove packages from your notebook's environment, or change a package's version. See Conda's documentation for more details on these commands.
5. Import the packages that you add in order to start using them in your notebook:
import package name
Note: When installing conda on a Jupyter instance, keep in mind the configuration of your persistent disk. If you delete your Cloud Environment while retaining your persistent disk, you will still get rid of conda.
To learn more about setting up your persistent disk, read How to set up persistent disk storage for your analysis app.