0

I am working to incorporate the symspellpy package for spell checking and correcting large amounts of data. However, the package suggests using pkg_resources.resource_filename, which is no longer supported. Can you please provide guidance on how to access the necessary resources using the currently preferred method?

dictionary_path = pkg_resources.resource_filename("symspellpy", "frequency_dictionary_en_82_765.txt")
bigram_path = pkg_resources.resource_filename("symspellpy", "frequency_bigramdictionary_en_243_342.txt")

1 Answer 1

1

The replacement is the importlib_resources.files function. It is integrated in standard library from Python 3.9, as importlib.resources.files

If you just need to support Python 3.9 or newer, it's straightforward

import importlib.resources

importlib.resources.files(...)

Otherwise, if you want to support Python 3.8 and older, here's how you do it:

  1. add importlib_resources>=1.3; python_version < '3.9' to your dependencies (requirements.txt, setup.cfg, setup.py or pyproject.toml, depending how the project is organised)
  2. In your code, adapt as
import sys

if sys.version_info >= (3, 9):
    import importlib.resources as importlib_resources
else:
    import importlib_resources

importlib_resources.files(...)

See https://importlib-resources.readthedocs.io/en/latest/migration.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.