简体   繁体   English

对于setup.py脚本使用find_packages()和“requirements.txt”之间的区别

[英]Difference between using find_packages() vs “requirements.txt” for setup.py script

I've been working on packaging a python project to so I can install it on other systems in a lab. 我一直在打包一个python项目,所以我可以在实验室的其他系统上安装它。 In my research on how to go about creating the setup.py script, I've seen two methods. 在我关于如何创建setup.py脚本的研究中,我已经看到了两种方法。

1) use "pip freeze > requirements.txt" command; 1)使用“pip freeze> requirements.txt”命令; then "packages='requirements.txt'" in the setup script 然后在安装脚本中“packages ='requirements.txt'”

2) Simply using "packages=find_packages()" in the setup script 2)只需在设置脚本中使用“packages = find_packages()”即可

My question is, what is the difference between these two methods? 我的问题是,这两种方法有什么区别? It seems like "find_packages" does the same as "pip freeze" but does nothing in terms of installing a modules where there are none to begin with. 似乎“find_packages”与“pip freeze”的作用相同,但在安装没有任何内容的模块方面没有任何作用。

Can anyone explain how these two methods differ, or just explain what each one is doing so I can make a more informed decision on which method to use? 任何人都可以解释这两种方法有何不同,或者只是解释每个方法的作用,以便我可以就使用哪种方法做出更明智的决定?

Thanks! 谢谢!

use "pip freeze > requirements.txt" command; 使用“pip freeze> requirements.txt”命令; then "packages='requirements.txt'" in the setup script 然后在安装脚本中“packages ='requirements.txt'”

Even assuming that by packages='requirements.txt' you mean packages=open('requirements.txt').read().splitlines() , that is absolutely the wrong thing to do, and I hope that you've simply been misreading whatever sources you've consulted rather than such blatantly wrong information actually being posted somewhere. 即使假设通过packages='requirements.txt'你的意思是packages=open('requirements.txt').read().splitlines() ,这绝对是错误的做法,我希望你只是简单地做过误读了你所咨询的任何来源,而不是实际上在某处发布的这种公然错误的信息。

The purpose of the packages keyword to the setup() function is to tell setuptools what directories of Python code in your repository are to be included when distributing & installing your project. setup()函数的packages关键字的目的是告诉setuptools在分发和安装项目时,将包含存储库中Python代码的哪些目录。 For most simple cases, packages=find_packages() is all you need. 对于大多数简单的情况,只需要packages=find_packages()

requirements.txt , on the other hand, is supposed to contain a list of other people's projects that your project depends on (and it should really be hand-crafted rather than redirecting pip freeze into it like a lobotomized chimp). 另一方面, requirements.txt应该包含你的项目所依赖的其他人的项目列表(它应该是手工制作的,而不是将像pip freeze重新定向到它中,就像一个切叶的黑猩猩)。 The correct setup() keyword to pass its contents to is install_requires , which is what causes your project's dependencies to also be installed whenever someone installs your project. 将其内容传递给install_requires的正确setup()关键字是导致项目依赖性也会在某人安装项目时安装的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM