So it turns out the code runs fine and VS Code's pylance extension wrongly showed a hint underline saying the module would not be imported, and I trusted it. Sorry for wasting everyone's time.