导入 Python 包以在笔记本中使用¶
Snowflake Notebooks manages the Python packages used in your notebook environment. You can import third-party packages listed in the Snowflake Anaconda channel (https://repo.anaconda.com/pkgs/snowflake/). For information on importing packages in Container Runtime, see Notebooks on Container Runtime.
导入包的注意事项
- Packages that you add to a notebook are available only to that notebook. If you want to use the same package in a different notebook, you must add the same packages again to that notebook.
- After you add a new package, you must restart the notebook session. Snowflake recommends that you add your package at the top of your notebook at the start of your analysis.
预安装的包
By default, Snowflake Notebooks use Python 3.9. Notebook environments come pre-packaged with common libraries for data science and machine learning, such as altair, pandas, numpy, snowflake-snowpark-python, and Streamlit (https://docs.streamlit.io/library/api-reference).
从 Anaconda 导入包¶
After your organization administrator accepts the terms, you can import libraries to use in Snowflake Notebooks.
-
Sign in to Snowsight.
-
In the navigation menu, select Projects » Notebooks.
-
选择您想要安装 Python 包的特定笔记本。
-
Select Packages menu at the top of your notebook.
-
Search for packages listed in the Snowflake Anaconda channel (https://repo.anaconda.com/pkgs/snowflake/).
-
Select a package to install it for use in your notebook, and optionally change the default package version in the list of Installed Packages.
Packages installed by you appear under Installed Packages.

After the package is added, it may take some time to be installed. After it is installed, you will see a confirmation message and you can then import and use the libraries in a Python cell.
从 Snowflake 暂存区导入包¶
在仓库和容器运行时上,如果您需要的包不是预安装包的一部分并且在 Anaconda 通道中不可用,您可以从某个暂存区导入包。
以下限制适用:
- 包导入器仅适用于 Python 模块和文件夹。
.tar.gzfiles are not supported.- 仓库运行时不支持 Wheel 文件。
请按照以下步骤添加其他包:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Notebooks.
- 选择您想要安装 Python 包的特定笔记本。
- Select the Packages menu at the top of your notebook.
- Select the Stage Packages tab.
- 输入舞台上文件的路径。
After the package is added, you can now import and use the libraries in a Python cell. See this in action in the import packages from stage (https://github.com/Snowflake-Labs/snowflake-demo-notebooks/blob/main/Import%20Package%20from%20Stage/Import%20Package%20from%20Stage.ipynb) tutorial notebook.
Now that all your packages are installed, start coding in your notebook.
