From c72ee9091e80ce458e15061dc57b73cd101b2298 Mon Sep 17 00:00:00 2001 From: Dong Zhou Date: Tue, 18 May 2021 22:12:41 +0800 Subject: [PATCH] fix picker error on importlib loaded module --- qlib/utils/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qlib/utils/__init__.py b/qlib/utils/__init__.py index 77857182d..fe039df4f 100644 --- a/qlib/utils/__init__.py +++ b/qlib/utils/__init__.py @@ -8,6 +8,7 @@ from __future__ import print_function import os import pickle import re +import sys import copy import json import yaml @@ -178,8 +179,10 @@ def get_module_by_module_path(module_path: Union[str, ModuleType]): module = module_path else: if module_path.endswith(".py"): - module_spec = importlib.util.spec_from_file_location("", module_path) + module_name = "dummy" + module_spec = importlib.util.spec_from_file_location(module_name, module_path) module = importlib.util.module_from_spec(module_spec) + sys.modules[module_name] = module module_spec.loader.exec_module(module) else: module = importlib.import_module(module_path)