Improve package import compatibility (#10052)

This update is to fix package import compatibility issue, such as
paddleocr & detectron2.

with this updates, detectron2 can be imported along side with paddleocr.
pull/10059/head
Bryan YW 2023-05-29 18:34:47 +08:00 committed by GitHub
parent 013870d9bc
commit 44316ac7fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -27,9 +27,17 @@ import logging
import numpy as np
from pathlib import Path
tools = importlib.import_module('.', 'tools')
ppocr = importlib.import_module('.', 'ppocr')
ppstructure = importlib.import_module('.', 'ppstructure')
def _import_file(module_name, file_path, make_importable=False):
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if make_importable:
sys.modules[module_name] = module
return module
tools = _import_file('tools', os.path.join(__dir__, 'tools/__init__.py'), make_importable=True)
ppocr = importlib.import_module('ppocr', 'paddleocr')
ppstructure = importlib.import_module('ppstructure', 'paddleocr')
from tools.infer import predict_system
from ppocr.utils.logging import get_logger