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

error out if sentencepiece is not installed #733

Merged
merged 3 commits into from
Apr 10, 2020

Conversation

zhangguanheng66
Copy link
Contributor

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.

try:
import sentencepiece as spm
except ImportError:
print("Please install sentencepiece")
Copy link
Contributor

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

try:
import sentencepiece as spm
except ImportError:
print("Please install sentencepiece")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

import sentencepiece as spm
except ImportError:
print("Please install sentencepiece")
raise
Copy link
Contributor

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?

@cpuhrsch cpuhrsch changed the title import sentencepiece only when it's used error out if sentencepiece is not installed Apr 10, 2020
@cpuhrsch
Copy link
Contributor

cpuhrsch commented Apr 10, 2020

I'd move this logic into the top-level "init" so you can be sure it's run immediately on import.

@zhangguanheng66
Copy link
Contributor Author

Fix #717 and partially #703

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

Successfully merging this pull request may close these issues.

None yet

2 participants