Fehlerbehebung Aspose.Font FOSS for Python

Fehlerbehebung Aspose.Font FOSS for Python

Importfehler

ModuleNotFoundError: No module named 'aspose_font'

Das Paket ist nicht in der aktiven Python-Umgebung installiert. Installieren Sie es:

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

Stellen Sie sicher, dass Sie in die richtige virtuelle Umgebung installieren, falls Sie eine verwenden.

ImportError: cannot import name 'FontType' from 'aspose_font'

FontType wird aus dem Top-Level aspose_font-Paket exportiert. Verwenden Sie:

from aspose_font import FontType  # correct

Wenn Sie diesen Fehler sehen, stellen Sie sicher, dass aspose-font>=1.0.0 in Ihrer aktiven Umgebung installiert ist.


Fehler beim Laden von Schriftarten

FontLoadException beim Aufruf von FontLoader.open()

Mögliche Ursachen:

  • Der Dateipfad ist falsch oder die Datei existiert nicht
  • Die Datei ist beschädigt oder hat einen nicht standardmäßigen Header
  • Sie haben ein Bytes-Objekt übergeben, das keine gültige Schriftart ist

Überprüfen Sie, ob die Datei vor dem Laden existiert:

import os
from aspose_font import FontLoader

path = "MyFont.ttf"
if not os.path.exists(path):
    raise FileNotFoundError(path)
font = FontLoader.open(path)

Probleme mit Backslashes in Windows-Pfaden

Verwenden Sie rohe Zeichenketten oder Vorwärtsschrägstriche unter Windows:

font = FontLoader.open(r"C:\Fonts\MyFont.ttf")
# or
font = FontLoader.open("C:/Fonts/MyFont.ttf")

API Fehler

AttributeError: 'Font' object has no attribute 'ttf_tables'

ttf_tables ist eine Eigenschaft von TtfFont, nicht von der Basisklasse Font. Verwenden Sie eine Typannotation:

from aspose_font import TtfFont
ttf_font: TtfFont = FontLoader.open("MyFont.ttf")
tables = ttf_font.ttf_tables

NotImplementedError von Font.to_bytes()

Font.to_bytes(font_type) wirft NotImplementedError nur, wenn es auf der abstrakten Basisklasse aufgerufen wird. Alle konkreten Schriftklassen (TtfFont, CffFont, WoffFont, Woff2Font, usw.) implementieren to_bytes() und geben die Font-Bytes zurück. Wenn Sie FontLoader.open() aufrufen, erhalten Sie eine konkrete Instanz — rufen Sie to_bytes() direkt auf, oder verwenden Sie FontConverter.convert(), um das Format zuerst zu ändern:

from aspose_font.converter import FontConverter  # internal API — may change between releases
from aspose_font import FontType

woff2 = FontConverter.convert(font, FontType.WOFF2)

Siehe auch

 Deutsch