Skip to content

Instantly share code, notes, and snippets.

@codeskyblue
Created July 28, 2015 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeskyblue/2750eb2228c692e2f492 to your computer and use it in GitHub Desktop.
Save codeskyblue/2750eb2228c692e2f492 to your computer and use it in GitHub Desktop.
Find python lib path
#! /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