#330·pipreqs

mypy cache folder causes generated requirements to be empty

Author: cebtenzzreCreated Oct 14, 2022Updated Jun 3, 2026

Related to #73.

Steps to reproduce

  • Create foo.py:
python
import requests
  • Run the following commands:
$ pipreqs --print
requests==2.28.1
INFO: Successfully output requirements

$ mypy foo.py
Success: no issues found in 1 source file

$ pipreqs --print

INFO: Successfully output requirements

I would expect 'requests' to still be in the generated requirements after running mypy.

Description

Since mypy creates a subfolder called .mypy_cache/3.10/requests, pipreqs will add it to 'candidates' which causes the import to be satisfied, even though foo.py is obviously not going to attempt to import that folder. Ignoring .mypy_cache is the simple fix, but maybe folders shouldn't be considered packages unless they contain an __init__.py? https://github.com/bndr/pipreqs/blob/a593d27e3d9fcdecc0fbf385ef43116cccad71ec/pipreqs/pipreqs.py#L104-L108 https://github.com/bndr/pipreqs/blob/a593d27e3d9fcdecc0fbf385ef43116cccad71ec/pipreqs/pipreqs.py#L143-L144