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

使用Poetry 1.6.1为Python库添加SQL文件以支持Pip安装后访问

如何用Poetry 1.6.1在Python库中包含SQL文件

问题场景

我开发了一个包含SQL文件的Python库,希望用户通过Pip安装该库后能够访问这些文件,当前使用Poetry 1.6.1构建该库。

尝试了以下配置但未生效:

[tool.poetry.include]
# Include the SQL files in the package
include = [
    "my_library/queries/*.sql"
]

出现错误:

The Poetry configuration is invalid:
  - [include] {'include': ['my_library/queries/*.sql']} is not of type 'array'

解决方法

错误源于[tool.poetry.include]区块的语法错误,Poetry要求该区块直接使用数组格式,无需嵌套include键。以下是两种正确的配置方式:

方式一:键值对格式

[tool.poetry.include]
"my_library/queries/*.sql" = "*"

方式二:数组列表格式

[tool.poetry.include]
- "my_library/queries/*.sql"

验证步骤

配置完成后,运行poetry build命令生成包,然后检查生成的wheel或sdist文件,确认SQL文件已被正确包含在内。若需要更精细的包数据配置,也可添加以下可选内容:

[tool.poetry.package.data]
"my_library.queries" = ["*.sql"]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 10:53:13