skip to Main Content

I am trying to use .pyi stub files in VSCode, and I have the
following file structure.
When I try to import a .pyi in .py script, e.g. in Hellomath.py, I use: import stubshome.Hellomath.
But I get the error ModuleNotFoundError: No module named 'stubshome.Hellomath'.

How can this issue be resolved?

2

Answers


  1. I don’t think what you’re trying to do is possible. Stub files are PyCharm’s version of implementing interfaces (that are absent in Python itself), they are useful only in development environment, that is specifically catered torwards making a use of them (mainly PyCharm). Vanilla Python interpreter, which I assume you run here, has no idea of how to handle such files – so it doesn’t recognise them as modules.

    Login or Signup to reply.
  2. You can create a typings folder in the root directory to hold the .pyi stub files.

    Of course, you can also change the following setting too.

        // Path to directory containing custom type stub files.
        "python.analysis.stubPath": "typings",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search