From: Gabriel Genellina on
En Thu, 04 Feb 2010 01:00:56 -0300, Hidura <hidura(a)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

From: Hidura on
Thanks, I read it and try to put my code in the correct form, but now give
me another error, inside the Writer Package says:
"ValueError: Attempted relative import in non-package", if somebody knows a
clue of how fix it i will glad to read opinions. [?]

On Thu, Feb 4, 2010 at 2:11 AM, Gabriel Genellina <gagsl-py2(a)yahoo.com.ar>wrote:

> En Thu, 04 Feb 2010 01:00:56 -0300, Hidura <hidura(a)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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



--
Hidura
From: Gabriel Genellina on
En Thu, 04 Feb 2010 12:40:41 -0300, Hidura <hidura(a)gmail.com> escribi�:

> Thanks, I read it and try to put my code in the correct form, but now
> give
> me another error, inside the Writer Package says:
> "ValueError: Attempted relative import in non-package", if somebody
> knows a
> clue of how fix it i will glad to read opinions. [?]

You say that Writer is a package, but apparently Python disagrees. A
package is not just "a directory containing an __init__.py file", this is
half the truth. Python must be *aware* of such file, and this happens when
you import the package.

If you directly run a script from inside a package, Python does not know
that it belongs to a package, and treats it as a simple, lonely script. In
that case, relative imports won't work.

Put the "main" script (the one that you directly execute) outside the
package. It can be as small as this, if you want:

from some.package import main
main()

--
Gabriel Genellina

From: Ben Finney on
"Gabriel Genellina" <gagsl-py2(a)yahoo.com.ar> writes:

> If you directly run a script from inside a package, Python does not
> know that it belongs to a package, and treats it as a simple, lonely
> script. In that case, relative imports won't work.

Which I consider to be a bug. Fortunately, it's already addressed in PEP
366 <URL:http://www.python.org/dev/peps/pep-0366/>. Unfortunately, it
involves more hackish boilerplate at the top of the program, and is only
available in Python 2.6+.

--
\ “Ignorance more frequently begets confidence than does |
`\ knowledge.” —Charles Darwin, _The Descent of Man_, 1871 |
_o__) |
Ben Finney
From: Hidura on
Thanks i middle resolve the problem, and i going to read the PEP-366 i've
been read the 328, i will kept informed of the progresses.

Thanks again for the help [?]

On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney
<ben+python(a)benfinney.id.au<ben%2Bpython(a)benfinney.id.au>
> wrote:

> "Gabriel Genellina" <gagsl-py2(a)yahoo.com.ar> writes:
>
> > If you directly run a script from inside a package, Python does not
> > know that it belongs to a package, and treats it as a simple, lonely
> > script. In that case, relative imports won't work.
>
> Which I consider to be a bug. Fortunately, it's already addressed in PEP
> 366 <URL:http://www.python.org/dev/peps/pep-0366/>. Unfortunately, it
> involves more hackish boilerplate at the top of the program, and is only
> available in Python 2.6+.
>
> --
> \ “Ignorance more frequently begets confidence than does |
> `\ knowledge.” —Charles Darwin, _The Descent of Man_, 1871 |
> _o__) |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>



--
Hidura