Pylint: Relative import should be

pistacchio picture pistacchio · May 4, 2012 · Viewed 11.2k times · Source

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

Answer

glglgl picture glglgl · May 4, 2012

Python 2.5 introduces relative imports. They allow you to do

from .entity import Entity