Problem with __init__.py in Python3.1

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Feb 4 07:11:06 CET 2010


En Thu, 04 Feb 2010 01:00:56 -0300, Hidura <hidura at gmail.com> escribió:

> Good evening list, I have a really big trouble with the imports in the  
> 3.1
> version(Notes: In the older 2.64 theres no problems), I have two  
> packages,
> the first package Utilities who contains Writer the second package,  
> Writers
> contain the module tagmanip(What is imported in the best way inside the
> __init__.py of the Writer), when i make  the import inside the writer
> everything is ok, but from the Utilities package the errors says:
> "ImportError: No module named tagsmanip".
> I don't understand why this is happening, if somebody could help me i  
> will
> glad to hear any suggestion.

In Python 3.x, "absolute" import is enabled by default (2.6 uses a mix of  
relative and absolute imports).
To import sibling modules in a package, or modules in a subpackage, you  
have to use relative imports:

 from . import tagmanip
 from .Writers import tagmanip

See PEP328 http://www.python.org/dev/peps/pep-0328/

-- 
Gabriel Genellina




More information about the Python-list mailing list