Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. In my research on how to go about creating the setup.py script, I've seen two methods.

1) use "pip freeze > requirements.txt" command; then "packages='requirements.txt'" in the setup script

2) Simply using "packages=find_packages()" in the setup script

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.

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!

like image 328
5nizzard Avatar asked Dec 24 '22 11:12

5nizzard


1 Answers

use "pip freeze > requirements.txt" command; then "packages='requirements.txt'" in the setup script

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.

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. For most simple cases, packages=find_packages() is all you need.

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). 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.

like image 77
jwodder Avatar answered Dec 28 '22 05:12

jwodder