docker 动态地址调用tool

This commit is contained in:
jeremygan2021
2025-11-26 21:13:34 +08:00
parent 7236912a53
commit eb47ab4fe6

View File

@@ -357,8 +357,15 @@ def convert_to_binary_data(image_path: str, width: int = 400, height: int = 300,
二进制数据
"""
try:
# 动态导入image_converter模块
spec = importlib.util.spec_from_file_location("image_converter", "/Users/jeremygan/Desktop/python_dev/luna2025/tool/image_converter.py")
# 动态导入image_converter模块 - 使用相对路径
import os
# 获取当前文件的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建到tool目录的路径
tool_dir = os.path.join(current_dir, "..", "tool")
image_converter_path = os.path.join(tool_dir, "image_converter.py")
# 导入模块
spec = importlib.util.spec_from_file_location("image_converter", image_converter_path)
image_converter = importlib.util.module_from_spec(spec)
spec.loader.exec_module(image_converter)