安装 Snowflake CLI¶
本主题介绍如何在 支持的平台 上安装 Snowflake CLI。请注意,Snowflake CLI 目前不适用于 AIX 系统。
Snowflake 建议使用二进制安装方法(例如包管理器)以在您的系统上安装 Snowflake CLI。您可以从官方 Snowflake CLI 存储库 下载二进制安装程序。
要求¶
您必须拥有一个有效的 Snowflake 账户,才能使用 Snowflake CLI。
要在 Snowflake 中使用 Snowflake CLI 运行 Streamlit,您必须拥有一个有权使用 Streamlit 的 Snowflake 账户。
要在 Snowflake 中使用 Snowflake CLI 运行 Snowpark Container Services,您必须拥有一个具有使用 Snowpark Container Services 权限的 Snowflake 账户。
小技巧
如果 Snowflake 账户需要 MFA(多重身份验证),Snowflake CLI 需要对每个命令进行批准。您可以使用 MFA 缓存,要求每四个小时才进行一次身份验证。有关更多信息,请参阅 使用多重身份验证 (MFA)。
使用包管理器安装 Snowflake CLI¶
要使用特定于平台的包管理器安装 Snowflake CLI,请使用以下程序之一:
使用 Linux 包管理器进行安装¶
如果使用的是 Linux 操作系统,则可以使用支持以下内容的包管理器安装 Snowflake CLI:
deb
包、rpm
包。
使用 deb
包管理器安装 Snowflake CLI:
从 Snowflake CLI 存储库 下载 Snowflake CLI
deb
。通过运行以下命令安装该包:
sudo dpkg -i snowflake-cli-<version>.deb
使用 rpm
包管理器安装 Snowflake CLI:
从 Snowflake CLI 存储库 下载 Snowflake CLI
rpm
包。通过运行以下命令安装该包:
sudo rpm -i snowflake-cli-<version>.rpm
要验证软件是否安装成功,请运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
使用 MacOS 包安装程序进行安装¶
要在 MacOS 中安装 Snowflake CLI,请执行以下操作:
从 Snowflake CLI 存储库 下载 Snowflake CLI 安装程序。
运行安装程序并按照说明安装 Snowflake CLI。
要验证软件是否安装成功,请打开新终端并运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
使用 Windows 安装程序进行安装¶
要在 Windows 中安装 Snowflake CLI,请执行以下操作:
从 Snowflake CLI 存储库 下载 Snowflake CLI 安装程序。
运行安装程序并按照说明安装 Snowflake CLI。
要验证软件是否安装成功,请打开新终端并运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
使用 Homebrew 安装¶
如果使用的是 Mac 操作系统,则可以使用 Homebrew (https://brew.sh/) 安装 Snowflake CLI。
如有必要,请安装 Homebrew (https://brew.sh/)。
授予 Homebrew 对 Snowflake CLI 存储库的访问权限,并运行以下命令:
brew tap snowflakedb/snowflake-cli brew update
要安装 Snowflake CLI,请运行以下命令:
brew install snowflake-cli
要验证软件是否安装成功,请运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
高级本地安装¶
您还可以使用以下任一项安装 Snowflake CLI 作为 Python 包:
Snowflake 建议仅出于开发目的或无法在您的环境中安装二进制文件时将其安装为 Python 包。
使用 pip (PyPi) 安装¶
备注
此方法修改了安装 Snowflake CLI 的 Python 环境。请考虑使用 pipx 代替,以避免依赖冲突。
要使用 pip
安装 Snowflake CLI,您必须安装 Python (https://python.org) 3.10 或更高版本。
运行以下 shell 命令:
pip install snowflake-cli
要验证软件是否安装成功,请运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
使用 pipx 安装¶
pipx (https://github.com/pypa/pipx) 可替代 pip
,可在隔离的虚拟环境中安装并执行 Python 包。因此,使用 pipx
安装 Snowflake CLI 并不会修改您当前的 Python 环境。
要使用 pipx
安装 Snowflake CLI,您必须安装 pipx (https://github.com/pypa/pipx)。
运行以下 shell 命令:
pipx install snowflake-cli
要验证软件是否安装成功,请运行以下命令:
snow --help
Usage: snow [OPTIONS] COMMAND [ARGS]... Snowflake CLI tool for developers. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --version Shows version of the Snowflake CLI │ │ --info Shows information about the Snowflake CLI │ │ --config-file FILE Specifies Snowflake CLI configuration file that should be used [default: None] │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │ │ --help -h Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ app Manages a Snowflake Native App │ │ connection Manages connections to Snowflake. │ │ cortex Provides access to Snowflake Cortex. │ │ git Manages git repositories in Snowflake. │ │ notebook Manages notebooks in Snowflake. │ │ object Manages Snowflake objects like warehouses and stages │ │ snowpark Manages procedures and functions. │ │ spcs Manages Snowpark Container Services compute pools, services, image registries, and image repositories. │ │ sql Executes Snowflake query. │ │ stage Manages stages. │ │ streamlit Manages a Streamlit app in Snowflake. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
安装命令自动补全功能¶
Snowflake CLI 支持标准 shell tab 补全功能。
要将自动补全功能安装至 Snowflake CLI,请执行以下步骤:
运行
snow --install-completion
命令:snow --install-completion
zsh completion installed in <user home>/.zfunc/_snow Completion will take effect once you restart the terminal
运行
snow --show-completion
命令以生成需要添加到 shell 配置文件的命令(.bashrc
、.bash_profile
、.zshrc
等):snow --show-completion
_snow_completion() { local IFS=$' ' COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ COMP_CWORD=$COMP_CWORD \ _SNOW_COMPLETE=complete_bash $1 ) ) return 0 } complete -o default -F _snow_completion snow
选择并复制命令输出文本。
打开您在此示例中的 shell 配置文件
.bashrc
,并粘贴复制的文本:export SHELL=/bin/bash ... _snow_completion() { local IFS=$' ' COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ COMP_CWORD=$COMP_CWORD \ _SNOW_COMPLETE=complete_bash $1 ) ) return 0 } complete -o default -F _snow_completion snow
保存文件。
要激活 tab 补全功能,请重新启动您的 shell 配置文件的 shell 或
source
,例如:source ~/.bashrc
要测试该功能,请输入 snow 命令,然后输入
TAB
,如下所示:snow app [TAB]
deploy init open run teardown version