Search code examples
pythonpylint

pylint Cannot import custom module and function (no-name-in-module)


I have the structure:

 |- file run_app.py

 |- folder 'tasks'

 |-- file app.py

There is a string in run_app.py:

import tasks.app

And pylint alerts that

run_app.py:8:0: E0611: No name 'app' in module 'tasks' (no-name-in-module)

When I rename tasks to taskss, the error disappears. Whats this? How to fix this strange behavior if I want to name the folder exactly 'tasks'?


Solution

  • Try to include an __init__.py file in the folder.

    Reason:

    The __init__.py files are required to make Python treat the directories as containing packages.

    Structure:

    package_name/
      __init__.py
      foo.py
      subpackage/
        other.py
    

    More info and examples here: https://docs.python.org/3/tutorial/modules.html#packages