Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacy_nlp_engine: missing spacy.cli #1487

Closed
tigersoldier opened this issue Nov 23, 2024 · 4 comments
Closed

spacy_nlp_engine: missing spacy.cli #1487

tigersoldier opened this issue Nov 23, 2024 · 4 comments

Comments

@tigersoldier
Copy link

Describe the bug
In spacy_nlp_engine.py, it only imports spacy but calls spacy.cli.download:

This will throw the following exception for spacy <= 3.7.0

    @staticmethod
    def _download_spacy_model_if_needed(model_name: str) -> None:
        if not (spacy.util.is_package(model_name) or Path(model_name).exists()):
            logger.warning(f"Model {model_name} is not installed. Downloading...")
>           spacy.cli.download(model_name)
E           AttributeError: module 'spacy' has no attribute 'cli'

.venv/lib/python3.10/site-packages/presidio_analyzer/nlp_engine/spacy_nlp_engine.py:65: AttributeError

Spacy 3.7.1 has spacy.cli imported when you import spacy only. So either fixed the code to explicitly import spacy.cli, or update the dependency requirement to depend on spacy>=3.7.1

To Reproduce
Steps to reproduce the behavior:

  1. Install spacy==3.7.0
  2. Call create_engine that triggers this path

Expected behavior
Should not throw this exception

Screenshots
N/A

Additional context
N/A

@omri374
Copy link
Contributor

omri374 commented Nov 25, 2024

Thanks, this is a change in behavior that the spaCy team quickly reverted:
explosion/spaCy#13039
explosion/spaCy#13040

@omri374
Copy link
Contributor

omri374 commented Nov 25, 2024

As far as I know, this issue happens only in version 3.7.0, so 3.6.9 and 3.7.1 should still work.

@tigersoldier
Copy link
Author

tigersoldier commented Nov 27, 2024

You are right. So maybe disallowing spacy 3.7.0 in the project.toml should be good enough?

@omri374
Copy link
Contributor

omri374 commented Nov 28, 2024

Yes. Would you be interested in creating a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants