推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
timerring
0D
V2EX  ›  Python

pip 怎么解决两个第三方依赖库的版本冲突的问题

  •  
  •   timerring ·
    timerring · Apr 3, 2025 · 3153 views
    This topic created in 405 days ago, the information mentioned may be changed or developed.

    如题,俩库都不是自己写的:

    The conflict is caused by:
        google-genai 0.0.1 depends on pydantic<3.0.0dev and >=2.0.0
        fastapi 0.88.0 depends on pydantic!=1.7, !=1.7.1, !=1.7.2, !=1.7.3, !=1.8, !=1.8.1, <2.0.0 and >=1.6.2
    

    google-genai 是我要装的库,到 initial 的 0.0.1 版本也是 pydantic>=2.0.0

    另一个库是我要装的核心库,它从第一版就只要求 fastapi 0.88.0 ,对应要求则是 pydantic<2.0.0

    这种情况老哥们有什么解决的办法吗🤔

    13 replies    2025-04-09 13:02:52 +08:00
    iyaozhen
        1
    iyaozhen  
       Apr 3, 2025
    我理解是解决不了 只能让你另一个核心库升级
    renmu
        2
    renmu  
       Apr 3, 2025 via Android
    找找老版本,或者强制装试试,不一定用的 api 刚好被改了,不然就只能手动了。。
    InDom
        3
    InDom  
       Apr 3, 2025
    Docker
    Cooky
        4
    Cooky  
       Apr 3, 2025
    conda
    Insolitude
        5
    Insolitude  
       Apr 3, 2025 via Android
    有个邪道路子,手动下载 whl 文件,然后用 wheel 解压,更改依赖版本,然后重新打包安装,最后祈祷不会报错。当然也可以解压了改代码,更新到新版本
    Vegetable
        6
    Vegetable  
       Apr 3, 2025
    很难解决,fork 一下另一个库,把 fastapi 升级一下。
    ClericPy
        7
    ClericPy  
       Apr 5, 2025
    干过类似的,直接猴子补丁篡改人家源码或者挂补丁

    反正早年间不重复造轮子,晚年以后尽量不引用第三方的玩意,依赖冲突太麻烦了,很多 1.0 以前版本的更慎重,毕竟没 stable 的版本意味着一两个月以后就升级的面目全非的了
    iorilu
        8
    iorilu  
       Apr 5, 2025
    重搞个虚拟环境, 装你要的版本

    然后手动复制覆盖老版本
    tomczhen
        9
    tomczhen  
       Apr 5, 2025
    要么维护者升级,要么自己 fork 一份代码从源码安装,有冲突的代码还需要修复。
    jamos
        10
    jamos  
       Apr 5, 2025
    逐步提高 fastapi 版本,或者降低 google-genai 版本
    momocraft
        11
    momocraft  
       Apr 5, 2025
    pydantic 被太多东西依赖了 不如用新的 fastapi
    Martin123123
        12
    Martin123123  
       Apr 5, 2025
    优先建议 fastapi 升级,pydantic 2.0 可以手动该代码兼容历史的旧模块
    timerring
        13
    timerring  
    OP
       Apr 9, 2025
    感谢老哥们的回答,核心库的作者已经失联了,为了避免修改核心库带来的可能潜在更复杂的问题,最后我降了 google genai 的 sdk ,选择了已经 archived 的 google generative 的 sdk ,没有冲突了,勉强凑活能用。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5860 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 97ms · UTC 01:59 · PVG 09:59 · LAX 18:59 · JFK 21:59
    ♥ Do have faith in what you're doing.