Search code examples
pythonpylint

Pylint: Relative import should be


I'm checking a module with Pylint. The project has this structure:

/builder
    __init__.py
    entity.py
    product.py

Within product I import entity like this:

from entity import Entity

but Pylint laments that:

************* Module builder.product
W:  5,0: Relative import 'entity', should be 'builder.entity'

However from builder.entity import Entity doesn't recognize the package, and from ..builder.entity import Entity doesn't work either. What is Pylint complaining about? Thanks


Solution

  • Python 2.5 introduces relative imports. They allow you to do

    from .entity import Entity