How to find which pip package owns a file?

前端 未结 3 682
梦毁少年i
梦毁少年i 2021-01-03 23:47

I have a file that I suspect was installed by pip. How can I find which package installed that file?

In other words, I\'m looking for a command similar

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 00:24

    Try this!

    find_pkg_by_filename(){ for pkg in $(pip list | cut -d" " -f1) ; do if pip show -f "$pkg" | grep "$1" ; then echo "=== Above files found in package $pkg ===" ; fi ; done ; }
    
    find_pkg_by_filename somefilename
    

    Note that if you add -q to the grep, it will exit as soon as there's a match, and then pip will complain about broken pipes.

提交回复
热议问题