41

pip freeze是魔鬼

 3 years ago
source link: https://jiajunhuang.com/articles/2020_03_04-pip_list.md.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

pip freeze是魔鬼

很多用Python的项目,喜欢用 pip freeze > requirements.txt 来保存依赖,而不是手动维护文件,pip freeze 是魔鬼。

来看看一个项目依赖的简化版:

        A           B
    /      \     /      \
C             D             E

可以看到,依赖中可能会出现共同依赖。为啥说 pip freeze 是魔鬼呢?

  • 可能会列入无关紧要的,或者非项目所需的依赖
  • 把次级依赖的版本也写死了,当后来需要升级顶级依赖的时候,很难分辨需要升级哪些,因此不可维护

那么我建议的写法是什么样的呢?仅写入顶级依赖,比如:

flask==1.1.1
PyMySQL==0.9.3
SQLAlchemy==1.3.13
alembic==1.4.0
gevent==1.4.0
gunicorn==20.0.4
redis==3.4.1

这样虽然时间久了,次级依赖可能也会冲突,但是解决起来比上面说的要简单很多。


微信公众号
关注公众号,获得及时更新

Haskell TypeClass 笔记

重新捡起你那吃灰的树莓派

Tornado 源码阅读

JavaScript权威指南笔记

Python零碎知识汇总

C语言的位操作

分治

关于python的decorator和descriptor

程序设计实践笔记

Thinking Recursively

Block I/O

如何解读c的声明

关于输入法的猜想

C语言与抽象思维

C注意事项




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK