Last active
February 19, 2022 02:14
-
-
Save ernstki/a43d4c875c008e197027b4aff056ca6b to your computer and use it in GitHub Desktop.
pywhich - tell me where a Python library came from
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
pywhich - tell me where a Python package came from | |
Original author: Adam Anderson | |
Source: https://stackoverflow.com/a/42365058 | |
License: CC-BY-SA-4.0 | |
""" | |
from __future__ import print_function | |
GIST = 'https://gist.github.com/ernstki/a43d4c875c008e197027b4aff056ca6b' | |
def pywhich(module_name): | |
module = __import__(module_name, globals(), locals(), [], 0) | |
return module.__file__ | |
if __name__ == "__main__": | |
import sys | |
import argparse | |
parser = argparse.ArgumentParser( | |
description="print where a Python package comes from", | |
epilog="Source: {}".format(GIST)) | |
parser.add_argument('pkgs', metavar='PKG', nargs='+', | |
help='package(s) to look for') | |
opts = parser.parse_args() | |
for pkg in opts.pkgs: | |
try: | |
print(pywhich(pkg)) | |
except ImportError: | |
parser.error("No such module '{}'.".format(pkg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: