将 Anaconda 包添加到笔记本¶
The notebook environment includes a set of pre-installed Anaconda packages, such as Python and Streamlit.
If your notebook uses additional Anaconda packages, you must add those packages to your application package so that your notebook can access them.
You can add them while editing the notebook in development mode. You can also add the packages by providing an environment.yml file.
备注
如果 environment.yml 文件与笔记本位于同一目录中,它将覆盖依赖包列表,并且通过 Snowsight UI 添加的任何包都将被忽略。
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.
在开发模式下编辑笔记本时添加 Anaconda 包¶
You can add Anaconda packages to your notebook while editing it in development mode. We recommend using this method rather than adding packages to the environment.yml file, because the process is considerably simpler.
To do this, you use the Packages button in the notebook editor.
After installing your application locally from the live version, navigate to your notebook file within Snowsight and open it.
确保笔记本处于开发模式。有关开发模式的信息,请参阅 在声明式共享原生应用程序中编辑笔记本。
Click the Packages button in the top center of the notebook editor.
搜索要添加的包,然后将其选中。
现在,笔记本环境会在笔记本运行时自动加载选定的依赖项。
将 Anaconda 包添加到 environment.yml 文件¶
You can define your Python dependencies by creating an 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
备注
只能安装 ` Snowflake Anaconda 通道 <https://repo.anaconda.com/pkgs/snowflake/ (https://repo.anaconda.com/pkgs/snowflake/)>`_ 中列出的包。Snowflake 中的 Streamlit 不支持外部 Anaconda 频道。
使用 PUT 命令将您的 environment.yml 文件从本地计算机上传到应用程序包暂存区。environment.yml 文件必须与其配置的笔记本文件位于暂存区上的同一目录中。
将以下命令中的占位符替换为您自己的值。如果您的笔记本位于实时版本的根目录中,则不要在 live/ 之后包含目录路径。
PUT <file:///path/to/your/environment.yml> snow://package/<PACKAGE_NAME>/versions/live/<path/to/your/notebook> OVERWRITE=TRUE AUTO_COMPRESS=FALSE;