Installation

安装

此页面为 Python 安装 Aspose.HTML FOSS,并使用最小的 DOM 循环验证设置。


Prerequisites

RequirementDetail
Python3.10 或更高版本
pip任何最近的版本
操作系统Windows、Linux 或 macOS
原生依赖无 — 纯 Python 实现

1. 创建虚拟环境(推荐)

保持安装与系统 Python 隔离:

python -m venv .venv

激活它 — 在 Windows 上:

.venv\Scripts\activate

在 Linux/macOS 上:

source .venv/bin/activate

2. 安装软件包

从 PyPI 安装当前发布版本 (0.1.0):

git clone https://github.com/aspose-html-foss/Aspose.HTML-FOSS-for-Python.git
cd Aspose.HTML-FOSS-for-Python
pip install -e .

3. 验证安装

构建一个单元素文档并读取计算后的样式——如果此输出没有错误,则说明安装成功:

from aspose_html.dom import Document
from aspose_html.cssom import CSSStyleSheet

doc = Document()
el = doc.create_element("div")
el.set_attribute("id", "bar")
doc.append_child(el)

sheet = CSSStyleSheet()
sheet.replace_sync("#bar { color: blue }")
doc.attach_style_sheet(sheet)

print(el.get_computed_style().get_property_value("color"))

后续步骤

另请参阅

 中文