Add Anaconda Packages to a Notebook

The notebook environment has a set of pre-installed Anaconda packages, including Python and Streamlit. If your notebook uses additional Anaconda packages, you must add those packages to your application package so that your notebook can use them. You can either add the packages by providing an environment.yml file, or you can add them while editing the notebook in development mode.

Note

If an environment.yml file is present in the same directory as a notebook, it overwrites the list of dependent packages, and any packages added through the Snowsight UI are ignored.

Using an environment.yml file is recommended for production applications as it allows you to manage dependencies in source control. Using the UI is convenient for interactive development and testing.

Adding Anaconda packages to the environment.yml File

You can define your Python dependencies by creating a standard environment.yml file, and uploading it to the same stage directory as your notebook (.ipynb) file.

For information about creating an environment.yml file that includes your new packages, see Manage packages by using the environment.yml file.

Note

You can only install packages listed in the Snowflake Anaconda Channel. Streamlit in Snowflake does not support external Anaconda channels.

Use the PUT command to upload your environment.yml file from your local machine to the application package stage. The environment.yml file must be in the same directory on the stage as the notebook file it configures.

Replace the placeholders in the following command with your own values. If your notebook is at the root of the live version, do not include a directory path after live/.

PUT <file:///path/to/your/environment.yml> snow://package/<PACKAGE_NAME>/versions/live/<path/to/your/notebook> OVERWRITE=TRUE AUTO_COMPRESS=FALSE;
Copy

Adding Anaconda packages while editing the notebook in development mode

You can add Anaconda packages to your notebook while editing it in development mode. To do this, you use the Packages button in the notebook editor.

  1. After installing your application locally from the live version, navigate to your notebook file within Snowsight and open it.

  2. Make sure the notebook is in Development Mode. For information about development mode, see Editing Notebooks in Declarative Shared Native Applications.

  3. Click the Packages button in the top center of the notebook editor.

  4. Search for the package you want to add, and select it.

The notebook environment now automatically loads the selected dependencies when the notebook is run.