#!/usr/bin/env python # -*- coding: utf-8 -*- """ 测试导入是否正常 """ import sys import os # 添加当前目录到路径 current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, current_dir) print("测试1: 导入20分钟预测模块...") try: # 使用importlib动态加载 import importlib.util spec = importlib.util.spec_from_file_location( "predict_20min", os.path.join(current_dir, "20min", "predict.py") ) predict_20min = importlib.util.module_from_spec(spec) spec.loader.exec_module(predict_20min) print(" [成功] 20分钟预测模块导入成功") print(f" Predictor类: {predict_20min.Predictor}") except Exception as e: print(f" [失败] {e}") import traceback traceback.print_exc() print("\n测试2: 导入90天预测模块...") try: spec = importlib.util.spec_from_file_location( "predict_90day", os.path.join(current_dir, "90day", "predict.py") ) predict_90day = importlib.util.module_from_spec(spec) spec.loader.exec_module(predict_90day) print(" [成功] 90天预测模块导入成功") print(f" Predictor类: {predict_90day.Predictor}") except Exception as e: print(f" [失败] {e}") import traceback traceback.print_exc() print("\n测试3: 导入共享模块...") try: sys.path.insert(0, os.path.join(current_dir, "shared")) from shared.gat_lstm import GAT_LSTM print(" [成功] GAT_LSTM模型导入成功") print(f" GAT_LSTM类: {GAT_LSTM}") except Exception as e: print(f" [失败] {e}") import traceback traceback.print_exc() print("\n测试4: 测试API主程序...") try: spec = importlib.util.spec_from_file_location( "api_main", os.path.join(current_dir, "api_main.py") ) api_main = importlib.util.module_from_spec(spec) # 不执行module,只检查能否加载 print(" [成功] API主程序可以加载") except Exception as e: print(f" [失败] {e}") import traceback traceback.print_exc() print("\n全部测试完成!")