Replies: 7 comments 8 replies
-
要在 <代码执行> 模块中安装所需的依赖包,例如 from core.helper.code_executor.entities import CodeDependency
from core.helper.code_executor.code_executor import CodeExecutor
# 定义依赖包
mysql_connector_dependency = CodeDependency(name='mysql-connector-python', version='latest')
# 执行包含依赖包的代码
try:
result = CodeExecutor.execute_code(
language='python3',
preload='',
code='import mysql.connector\nprint(mysql.connector.__version__)',
dependencies=[mysql_connector_dependency]
)
print(result)
except CodeExecutionException as e:
print(f'代码执行失败: {e}') 这个代码片段展示了如何指定 请确保在执行代码时正确设置依赖包,以避免缺少依赖包导致的错误。 |
Beta Was this translation helpful? Give feedback.
-
是这个代码执行模块 |
Beta Was this translation helpful? Give feedback.
-
If it is to connect to a data source to retrieve data, it maybe better to use HTTP request node, or custom tool. |
Beta Was this translation helpful? Give feedback.
-
请问解决了吗?我也遇到了相同的问题 |
Beta Was this translation helpful? Give feedback.
-
已经解决,在 dify/docker/volumes/sandbox/dependencies 里添加需要的依赖, |
Beta Was this translation helpful? Give feedback.
-
<代码执行> 模块里面执行Python代码,但是依赖mysql-connector-python 包,内置没有该依赖包,导致执行报错
Beta Was this translation helpful? Give feedback.
All reactions