Is there any way to specify a custom target directory for pkg_resources to list pip packages? I want to be able to find packages which have been installed in a custom target directory using --target through something like pkg_resources.require() that already fed with a custom target directory.
What I don't want is to use:
setuptools.find_packagesas it's only usingsys.pathsetuptools.PEP420PackageFinder.find- Finding packages through traversing the directory names and files was not helping as well, as I need a more generic way of finding package namespaces.
I appreciate any help on this.
Update
Python 3.8 introduced
importlib.metadata, a module for querying the installed packages that supersedespkg_resources. Example usage:For Python 2.7 and Python >=3.5, there's a backport called
importlib-metadata:Original answer
The
pkg_resources.find_distributionsfunction (documented under Getting or Creating Distributions) accepts a target dir to search for packages in. Example:Scanning
my_target_dirwithpkg_resources.find_distributionsyields: