def find_modules_from_path(import_path):
import_from_path(import_path)
site_dirs = site.getsitepackages()
lib_dirs = [os.path.dirname(path) for path in site_dirs]
for module in sys.modules.values():
path = getattr(module, '__file__', '')
if path[-4:] in ('.pyo', '.pyc'):
path = path[:-1]
if path and os.path.exists(path):
if all(not path.startswith(lib_dir) for lib_dir in lib_dirs):
yield module
评论列表
文章目录