>

setuptools python issue FileNotFoundError: [Errno 2] No such file or directory: ‘requirements.txt’

Root cause

It’s caused by the fact that build is copying files to a temporary directory first. But it’s only copying the source/, README.md, setup.py, setup.cfg. It’s not copying requirements/.

Solution

build does the correct job here. After building the source dist, it checks whether the built result can be actually installed. And without including the files under requirements into the source dist, the source dist can not be installed and is thus unusable. Try it out:

$ python -m build --sdist  # builds fine, but the tar is broken:
$ cd dist
$ tar tf pkg-0.0.1.tar.gz | grep requirements  # will be empty

To fix, write a MANIFEST.in alongside the setup.py that includes requirements directory in the source dist.

This only concerns the source dist, as the wheel is built on host (your machine) already and does not contain a setup script anymore. Wheel building will also ignore the MANIFEST.in file.

hnidoaht-101

A 🦀 love open sources. Actually just a pet lover with passion to build the nice things.


By hn1Do@ht-0n3z3Roo11e, 2022-07-26