-
Notifications
You must be signed in to change notification settings - Fork 813
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
error out if sentencepiece is not installed #733
Conversation
torchtext/data/functional.py
Outdated
try: | ||
import sentencepiece as spm | ||
except ImportError: | ||
print("Please install sentencepiece") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use "ImportWarning" here
torchtext/data/functional.py
Outdated
try: | ||
import sentencepiece as spm | ||
except ImportError: | ||
print("Please install sentencepiece") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
torchtext/data/functional.py
Outdated
import sentencepiece as spm | ||
except ImportError: | ||
print("Please install sentencepiece") | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're raising the exception it'll fail after all, right? Did you try this with and without sentencepiece available?
I'd move this logic into the top-level "init" so you can be sure it's run immediately on import. |
Since sp is not released via conda, if users install torchtext's conda wheels, we don't force them to install sp until they use relevant API.