pipreqs icon indicating copy to clipboard operation
pipreqs copied to clipboard

Pip reqs doesn't work when import is not the same as the library name

Open kykyi opened this issue 2 years ago • 4 comments

Hello, found a bug when the module name to import is not the same as the library name, in this case the pyahorasick library.

To reproduce:

  1. import ahorasick into <file>.py in <dir>
  2. run pipreqs <dir>
  3. See there is both ahorasick (incorrect) and pyahorasick (correct)
  4. run pip install -r <dir>/requirements.txt
  5. See an error that no versions of ahorasick can be found.

ahorasick is the module from within the pyahorasick library. What I am guessing is happening is pipreqs is building the requirements based off import statements, and because in this case module name != library name it incorrectly requires ahorasick, and as that does not exists on pypi, results in an error.

Happy to (attempt to) contribute if someone can point me in the right direction 😄

kykyi avatar Oct 13 '22 13:10 kykyi

Hello,

I can confirm this with the pygithub module. It is not detected, as the import is import github.

I'm also grateful for any workarounds when it is not as easy to detect.

NielsKorschinsky avatar Oct 24 '22 12:10 NielsKorschinsky

pyahoarsick library is newer than the last commit in pipreqs repository. You should update MAPPING file.

As for github module, it is present in mapping file on line 681:

github:PyGithub

and this I do not understand.

mknorps avatar Nov 21 '22 11:11 mknorps

Yes, I saw the mapping too, but it somehow did not work.

NielsKorschinsky avatar Dec 02 '22 10:12 NielsKorschinsky

I have to correct, now with version 0.4.11 it works like a charm

NielsKorschinsky avatar Dec 02 '22 14:12 NielsKorschinsky