Created
July 28, 2015 08:16
-
-
Save codeskyblue/2750eb2228c692e2f492 to your computer and use it in GitHub Desktop.
Find python lib path
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 | |
# -*- coding: utf-8 -*- | |
# | |
# Author: hzsunshx | |
# Created: 2015-06-01 15:56 | |
""" | |
find python lib path | |
""" | |
import os | |
import sys | |
import argparse | |
def find(libname): | |
founds = [] | |
for path in sys.path: | |
if not os.path.isdir(path) or path.startswith('.'): | |
continue | |
for tgtname in os.listdir(path): | |
if tgtname.startswith('.'): | |
continue | |
name, ext = os.path.splitext(tgtname) | |
if name == libname: | |
yield os.path.join(path, tgtname) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser("find python package") | |
parser.add_argument('pkgname', help='package name') | |
args = parser.parse_args() | |
paths = find(args.pkgname) | |
for path in {}.fromkeys(paths).keys(): | |
print path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment