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

如何使用单个sed命令移除Python元数据文件中的依赖版本信息

解决方案

可以使用这条单个sed命令完成需求:

sed -E 's/(Requires-Dist: [^ (]+)(.*)/\1/' your_metadata_file.txt

命令解释

  • -E:启用扩展正则表达式语法,让括号等元字符无需额外转义,简化正则写法
  • 正则匹配逻辑:
    • (Requires-Dist: [^ (]+):捕获Requires-Dist: 开头,加上后续所有非空格、非左括号的字符(这部分就是依赖库的名称,比如hello、hello-world)
    • (.*):捕获库名之后的所有内容(包括版本号、括号、分号条件等)
    • \1:替换为第一个捕获组的内容,也就是只保留依赖库名称部分,去掉后面的版本和附加条件

输入示例

Requires-Python: >=3
Requires-Dist: hello (~=0.1.1)
Requires-Dist: bar (~=1.14)
Requires-Dist: hello-world (~=1.10)
Requires-Dist: test (~=1.1) ; python_version < "3.4"
Requires-Dist: test-bar
...

输出结果

Requires-Python: >=3
Requires-Dist: hello
Requires-Dist: bar
Requires-Dist: hello-world
Requires-Dist: test
Requires-Dist: test-bar
...

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 15:54:59