Python – ImportError: cannot import name. Can’t figure out why

blenderimportimporterrorpythonpython-3.x

I have three python files, in a folder.

My folder structure looks like so:

RenderAddon (folder)
---- __init__.py
---- config.py
---- QuickRenderAddon.py

I try to run __init__.py, but I get this error:

Error:

"RenderAddon\__init__.py", line 22
    from . import config
    ImportError: cannot import name 'config'

Complete traceback:

Traceback (most recent call last):
  File "D:\Programs\Blender_271\2.71\scripts\modules\addon_utils.py", line 299, in enable
    mod = __import__(module_name)
  File "C:\Users\EinarAune\AppData\Roaming\Blender Foundation\Blender\2.71\scripts\addons\RenderAddon\__init__.py", line 22, in <module>
    from . import config
ImportError: cannot import name 'config'

I can't figure out why. What's wrong?


__init__.py

if "bpy" in locals():
    import imp
    imp.reload(config)
    imp.reload(QuickRenderAddon)
    print("Reloaded multifiles")
else:
    from . import config
    from . import QuickRenderAddon
    print("Imported multifiles")

import bpy
import os

QuickRenderAddon.py

import bpy
import os
from . import config

No imports in config.py

Best Solution

from . import config will try to import a "config" name from __init__.py, you should instead do import config

Related Question