pip freeze 不依赖已安装的软件包
当我执行pip freeze
时,我得到了我显式安装的包以及那些依赖于这些包的包。
例如:
$ pip install fabric
...
$ pip freeze
Fabric==1.0.1
paramiko==1.7.6
pycrypto==2.3
好吧,但是后来我使用 pip install
在另一个环境上安装这个requirements.txt,删除最后两行后,我会得到相同的结果。
所以我的问题是:如何创建最简化的requirements.txt,其中不显示所有可计算的依赖项?
When I do pip freeze
I get the packages I've explicitly installed plus those packages that are dependencies of those packages.
For example:
$ pip install fabric
...
$ pip freeze
Fabric==1.0.1
paramiko==1.7.6
pycrypto==2.3
Ok fine but then I move to install this requirements.txt on another environment with pip install
I'd get the same result with the last 2 lines removed.
So my question is: how I can I create the most simplified requirements.txt where all calculable dependencies are not shown?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在有(免责声明:我做到了)。
您只需从 PyPI 安装
pip-chill
并从 Python 环境运行pip-chill
即可。如果您喜欢冒险并且不想固定版本(或想使用 pip-compile),您可以使用
pip-chill --no-version
,它会给您最低的要求适合您当前的环境。https://github.com/rbanffy/pip-chill
Now there is (disclaimer: I did it).
All you need is to install
pip-chill
from PyPI and runpip-chill
from your Python environment.If you are feeling adventurous and don't want to pin versions (or want to use pip-compile), you can use
pip-chill --no-version
and it'll give you the minimal requirements for your current environment.https://github.com/rbanffy/pip-chill
无法使用 pip 创建“最简化的requirements.txt” - 我不知道在这种情况下您是否需要它。
最好将所有包放在requirements.txt 中,因为您可以确定哪些依赖项版本适用于您的环境。
想想 paramiko 更新并破坏向后兼容性:你会遇到问题。
There is no way to create "the most simplified requirements.txt" with pip - and I don't know if you would need it in this case.
It is good to have all packages in the requirements.txt, because you are sure about what dependencies versions work with your environment.
Think about paramiko getting updated, and breaking backwards compatibilities: you would have problems.
我认为删除版本的简单方法是在运行
pip freeze
后剪切-d"=" -f1
。I think the simply way to remove version is cut
-d"=" -f1
after having runpip freeze
.pipdeptree 是另一种选择。
它会生成完整的requirements.txt(使用
pipdeptree -f
),如下所示:该文件有两个用途:
pip install
的传统requirements.txt;grep '^\w'requirements.txt
即可用作开发人员友好的软件包列表(如pip-chill
创建的列表)。pipdeptree is another option.
It produces full requirements.txt (with
pipdeptree -f
) like this:This file serves two purposes:
pip install
;pip-chill
) simply withgrep '^\w' requirements.txt
.