You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用df.to_sql()推送数据至Snowflake时提示pandas依赖缺失的问题

解决Snowflake-Connector提示缺失Pandas依赖的问题(已安装Pandas仍报错)

问题描述

在使用SQLAlchemy结合snowflake-connector将DataFrame写入Snowflake新表时,触发以下错误:

raise errors.MissingDependencyError(self._dep_name) snowflake.connector.errors.MissingDependencyError: Missing optional dependency: pandas

脚本中已导入pandas且其他模块可正常使用pandas,无法理解为何仍提示依赖缺失。

环境版本

snowflake-connector-python     3.0.2
snowflake-sqlalchemy           1.4.7
SQLAlchemy                     1.4.49

简化代码示例

import pandas as pd
from snowflake.connector.pandas_tools import pd_writer
from sqlalchemy.types import String
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    user='service account',
    password='password',
    account='account',
    database='database',
    schema='schema',
    warehouse='warehouse',
    role="role"
    ))
df.columns = map(lambda x: str(x).upper(), df.columns)

df.to_sql(name=table_name.lower(), con=engine, schema="schema", index=False, if_exists='append', method=pd_writer, dtype={'field': String})

engine.dispose()

解决方案

在终端或PowerShell中执行以下命令,安装包含pandas可选依赖的snowflake-connector-python版本:

pip install snowflake-connector-python[pandas]

注:snowflake-connector-python的pandas相关工具(如pd_writer)属于可选功能,需显式安装带[pandas]后缀的包版本,即使系统已单独安装pandas,连接器也需要该关联依赖才能正常调用相关功能。

内容的提问来源于stack exchange,提问作者Harry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 18:22:09