diff --git a/simplemma/strategies/dictionaries/trie_directory_factory.py b/simplemma/strategies/dictionaries/trie_directory_factory.py index 6d2c2ec..fb981c9 100644 --- a/simplemma/strategies/dictionaries/trie_directory_factory.py +++ b/simplemma/strategies/dictionaries/trie_directory_factory.py @@ -4,8 +4,14 @@ from pathlib import Path from typing import List, Mapping, Optional -from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found] -from platformdirs import user_cache_dir +try: + from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found] + from platformdirs import user_cache_dir + _dependencies_installed = True +except ImportError: + type BytesTrie = type + _dependencies_installed = False + from simplemma import __version__ as SIMPLEMMA_VERSION from simplemma.strategies.dictionaries.dictionary_factory import ( @@ -69,6 +75,9 @@ def __init__( specific subdirectory of the user's cache directory. """ + if not _dependencies_installed: + raise ImportError("trie_dictionary dependencies must be installed before using TrieDictionaryFactory") + if disk_cache_dir: self._cache_dir = Path(disk_cache_dir) else: