[Python] "pylint (import error)" while import a module in the same folder with VSCode

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm building my code in VSCode using python 3.7.3.

    The folder structure:

    project
    ├── main.py
    └── modules
    ├── __init__.py
    ├── foo.py
    └── boo.py


    In foo.py:

    import boo
    boo.printBoo()


    When I run foo.py it works. I can get the result I expect.

    This is boo

    But VSCode pops out:


    Unable to import 'boo' pylint(import-error)
    ​

    Though the code works, is there a way that I can get rid of pylint(import-error)?


    I have tried to change the import statement to

    from ..modules import boo as Boo


    error: attempted relative import with no known parent package
    ​

    and

    import modules.boo as Boo


    error: No module named 'modules'
    ​

    What is the problem, is it pylint's problem or did I misuse the import?

    Continue reading...

Compartilhe esta Página