在 Snowflake Notebooks 中进行故障排除¶
以下场景可帮助您排除使用 Snowflake Notebooks 时可能出现的问题。
笔记本总数超过 Snowsight 限制¶
当您账户中的笔记本总数超过 6,000 并刷新 Notebooks 列表时,会出现以下错误:
Result size for streamlit list exceeded the limit. Streamlit list was truncated.
用户仍可创建新笔记本;但是,Snowflake 建议您移除账户不再使用的笔记本。
更新包时出现笔记本(仓库运行时)错误¶
Snowflake 已弃用旧版 snowflake-ml
包,该包不再受支持。它已从包选择器中移除,并且在 Snowflake Anaconda 通道中不可用。如果您正在使用 snowflake-ml
并尝试添加、移除或更新笔记本中的包,这些笔记本将会失败,因为 snowflake-ml
已不再可用。
为了避免出现问题,请切换到 snowflake-ml-python
,这是 Snowflake ML 的正确包。
Plotly 错误¶
st.plotly_chart(fig, render_mode='svg')
WebGL is not supported by your browser - visit https://get.webgl.org for more info.
如果数据点超过 1,000 个,Plotly 将切换到 WebGL。
AttributeError:NoneType
¶
当单元格重命名为与笔记本中现有变量相同的名称时,会出现以下错误:
AttributeError: ‘NoneType’ object has no attribute ‘sql’
例如,在名为 cell1
的 Python 单元格中有如下内容:
session = get_active_session() #establishing a Snowpark session
如果将 cell2
重命名为“session”,并在 cell3
中引用“session”,Notebooks 会尝试引用“session”(单元格名称)而不是 Snowpark 会话,从而导致错误。
提前断开连接¶
笔记本会话作为存储过程运行。如果您的笔记本在 30 分钟超时前意外断开连接,您的 ACCOUNTADMIN 或仓库所有者可能已将 STATEMENT_TIMEOUT_IN_SECONDS 参数设置为特定值(例如 5 分钟),该值限制了仓库中所有语句(包括笔记本会话)的运行时间。该参数在仓库或账户级别设置,当同时为仓库和会话设置该参数时,将执行非零的最低值。
有关空闲时间设置的详细信息,请参阅 空闲时间和重新连接。
无法重新连接¶
如果浏览器未启用 Cookie,则在笔记本会话仍处于活动状态时(由于未活动而超时之前),无法自动重新连接。重新打开笔记本时,会显示一条错误消息:
Notebook connection lost and cannot reconnect. Restart or end session.
重新启动会话将结束当前的 EXECUTE NOTEBOOK 查询并启动新会话。结束会话将结束当前 EXECUTE NOTEBOOK 查询。
如果您不采取任何行动,当前 EXECUTE NOTEBOOK 查询将继续在仓库上运行,并显示在 Query History 中。
由于防火墙原因无法连接¶
当您尝试启动笔记本时,出现以下弹出窗口:
Something went wrong. Unable to connect. A firewall or ad blocker might be preventing you from connecting.
确保 *.snowflake.app
在您网络(包括内容筛选系统)的允许列表中,并且可以连接到 Snowflake。当此域列入允许列表时,您的应用程序可以不受任何限制地与 Snowflake 服务器通信。
此外,为防止连接到 Snowflake 后端出现任何问题,请确保网络配置中未阻止 WebSockets。
缺少包¶
如果您尝试在笔记本环境中使用未安装的包,单元格输出中会显示以下错误消息:
ModuleNotFoundError: Line 2: Module Not Found: snowflake.core. To import packages from Anaconda, install them first using the package
selector at the top of the page.
按照 导入 Python 包以在笔记本中使用 页面上的说明导入必要的包。
现有笔记本中缺少包¶
笔记本的新版本不断发布,并且笔记本会自动升级到最新版本。有时,升级旧笔记本时,笔记本环境中的软件包与升级不兼容。这可能会导致笔记本无法启动。
以下是缺少 Libpython
包时出现的错误消息示例:
SnowflakeInternalException{signature=std::vector<sf::RuntimePathLinkage> sf::{anonymous}::buildRuntimeFileSet(const sf::UdfRuntime&, std::string_view, const std::vector<sf::udf::ThirdPartyLibrariesInfo>&, bool):"libpython_missing", internalMsg=[XP_WORKER_FAILURE: Unexpected error signaled by function 'std::vector<sf::RuntimePathLinkage> sf::{anonymous}::buildRuntimeFileSet(const sf::UdfRuntime&, std::string_view, const std::vector<sf::udf::ThirdPartyLibrariesInfo>&, bool)'
Assert "libpython_missing"[{"function": "std::vector<sf::RuntimePathLinkage> sf::{anonymous}::buildRuntimeFileSet(const sf::UdfRuntime&, std::string_view, const std::vector<sf::udf::ThirdPartyLibrariesInfo>&, bool)", "line": 1307, "stack frame ptr": "0xf2ff65553120", "libPythonOnHost": "/opt/sfc/deployments/prod1/ExecPlatform/cache/directory_cache/server_2921757878/v3/python_udf_libs/.data/4e8f2a35e2a60eb4cce3538d6f794bd7881d238d64b1b3e28c72c0f3d58843f0/lib/libpython3.9.so.1.0"}]], userMsg=Processing aborted due to error 300010:791225565; incident 9770775., reporter=unknown, dumpFile= file://, isAborting=true, isVerbose=false}
要解决此错误,请尝试以下步骤:
刷新网页并重新启动笔记本。
如果问题仍然存在,请打开包选择器并检查所有已安装的包是否有效。在每个包的下拉菜单中,可以看到可用的版本。选择包的最新版本通常可以清除错误。
只读文件系统问题¶
一些 Python 库会将数据下载或缓存到本地用户目录。但是,默认用户目录 /home/udf
是只读的。要解决此问题,请将路径设置为 /tmp
,这是一个可写位置。请注意,用于设置写入目录的环境变量可能会因使用的库而有所不同。以下是已知存在此问题的库的列表:
matplotlib
HuggingFace
catboost
matplotlib 示例¶
使用 matplotlib 时,您可能会看到此警告:
Matplotlib created a temporary cache directory at /tmp/matplotlib-2fk8582w because the default path (/home/udf/.config/matplotlib) is
not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular
to speed up the import of Matplotlib and to better support multiprocessing.
使用此代码可将 MPLCONFIGDIR
变量设置为 /tmp/
,从而解决此警告:
import os
os.environ["MPLCONFIGDIR"] = '/tmp/'
import matplotlib.pyplot as plt
Huggingface 示例¶
使用 Huggingface 时,您可能会看到此警告:
Readonly file system: `/home/udf/.cache`
以下代码会将 HF_HOME
和 SENTENCE_TRANSFORMERS_HOME
变量设置为 /tmp/
,从而消除该错误:
import os
os.environ['HF_HOME'] = '/tmp'
os.environ['SENTENCE_TRANSFORMERS_HOME'] = '/tmp'
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Snowflake/snowflake-arctic-embed-xs")
使用 df.collect()
时输出信息过大¶
运行 df.collect()
时,单元格输出中显示以下消息:
MessageSizeError: Data of size 522.0 MB exceeds the message size limit of 200.0 MB.
This is often caused by a large chart or dataframe. Please decrease the amount of data sent to the browser,
or increase the limit by setting the config option server.maxMessageSize.
Click here to learn more about config options.
Note that increasing the limit may lead to long loading times and large memory consumption of the client's browser and the Streamlit server.
以下情况下,Snowflake Notebooks 会自动截断大型数据集单元格输出中的结果:
所有 SQL 单元格结果。
Python 单元格结果(如果是
snowpark.Dataframe
)。
上述单元格的问题在于 df.collect()
返回的是 List
而不是 snowpark.Dataframe
。列表不会自动截断。要解决这个问题,可直接输出 DataFrame 的结果。
df
在 Snowpark DataFrames 在上使用 df.to_pandas()
时,笔记本崩溃¶
运行 df.to_pandas()
时,所有数据都会加载到内存中,如果数据大小超过相关笔记本仓库的内存限制,可能会导致笔记本会话终止。
示例 1:将 Snowpark 表导出到 pandas DataFrame¶
data = session.table("BIG_TABLE")
df = data.to_pandas() # This may lead to memory error
示例 1 的解决方法¶
以下示例展示了如何重写代码,以使用 Snowpark pandas 读取表格。
# Import Snowpark pandas
import modin.pandas as pd
import snowflake.snowpark.modin.plugin
# Create a Snowpark pandas DataFrame from BIG_TABLE
df = pd.read_snowflake("BIG_TABLE")
# Keep working with your data using the pandas API
df.dropna()
示例 2:引用包含大量结果的 SQL 单元格¶
如果在名为 cell1
的 SQL 单元格中输入以下代码,输出结果为 5 亿行。
SELECT * from BIG_TABLE
然后,当您将结果提取到 pandas DataFrame 中时,笔记本会崩溃,因为数据太大,内存无法容纳:
df = cell1.to_pandas() # This may lead to memory error
一般来说,对于大型数据集,Snowflake 建议您避免使用 df.to_pandas()
。相反,要使用 pandas 对数据进行操作,请使用 Snowpark pandas API 和 Snowpark 优化仓库。通过 Snowpark pandas API,您可以直接在 Snowflake 中的数据上运行 pandas 代码,并使用 SQL 执行查询。这样,您就可以在笔记本内存不足的数据上运行 pandas 代码。
示例 2 的解决方法¶
在上述第二个单元格引用示例中,您可以先将 SQL 单元格结果转换为 Snowpark DataFrame。然后,再将其转换为 Snowpark pandas。
SELECT * from BIG_TABLE
snowpark_df = cell1.to_df()
df = snowpark_df.to_snowpark_pandas()
# Keep working with your data using the Snowpark pandas API
有关详细信息,请参阅 笔记本中的 pandas on Snowflake。
由于 VPN 分离隧道原因无法连接¶
如果您的 VPN 配置为使用分离隧道,则必须将 *.snowflake.com
和 *.snowflake.app
添加到网络策略允许列表中。