第六章 使用嵌入式 Python (三)
从 ObjectScript 调用嵌入式 Python 代码
使用 Python 库
嵌入式 Python 让可以轻松访问数以千计的有用库。通常称为“包”,它们需要从 Python 包索引 (PyPI) 安装到 <installdir>/mgr/python 目录中,然后才能使用。
例如,ReportLab Toolkit 是一个用于生成 PDF 和图形的开源库。以下命令使用软件包安装程序 irispip 在 Windows 系统上安装 ReportLab:
C:\InterSystems\IRIS\bin>irispip install --target C:\InterSystems\IRIS\mgr\python reportlab
在基于 UNIX 的系统上,使用:
$ pip3 install --target /InterSystems/IRIS/mgr/python reportlab
安装包后,可以使用 %SYS.Python 类的 Import() 方法在 ObjectScript 代码中使用它。
给定一个文件位置,以下 ObjectScript 方法 CreateSamplePDF() 创建一个示例 PDF 文件并将其保存到该位置。
.png)