Thank you for your answer Frank, I think I've found the problem. I was calling modules from inside subpackages, and I need to use them from outside, so I have package in PYTHONPATH. is that correct? But now I have another question: Can I execute an script inside subpackage1 importig modules from subpackage2?<br>
<br><div class="gmail_quote">2011/3/4 Frank Millman <span dir="ltr"><<a href="mailto:frank@chagford.com">frank@chagford.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
On February 28 2011 Rafael Durán Castañeda wrote<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I'm stil totally stuck with relative imports, i' ve tried the example tree<br>
from PEP 328 without any result:<br>
<br>
package/<br>
__init__.py<br>
subpackage1/<br>
__init__.py<br>
moduleX.py<br>
moduleY.py<br>
subpackage2/<br>
__init__.py<br>
moduleZ.py<br>
moduleA.py<br>
<br>
Assuming that the current file is either moduleX.py or<br>
subpackage1/__init__.py, following are correct usages of the new<br>
syntax:<br>
<br>
from .moduleY import spam<br>
from .moduleY import spam as ham<br>
from . import moduleY<br>
from ..subpackage1 import moduleY<br>
from ..subpackage2.moduleZ import eggs<br>
from ..moduleA import foo<br>
from ...package import bar<br>
from ...sys import path<br>
<br>
I always get:<br>
<br>
Traceback (most recent call last):<br>
File "moduleY.py", line 1, in <module><br>
from ..moduleA import a<br>
ValueError: Attempted relative import in non-package<br>
<br>
<br>
</blockquote>
<br>
Hi Rafael<br>
<br>
I only just noticed your message now. For some reason it did not appear on google.groups.<br>
<br>
I just tried it and it worked for me. This is what I did.<br>
<br>
I set up the above structure. I added a 'def spam()' to moduleY, 'def eggs()' to moduleZ, and 'def foo()' to moduleA.<br>
<br>
I pasted all of the 'from ... import ...' lines above into moduleX.<br>
<br>
In the same directory that contains the subdirectory 'package' I create a test script containing the following line -<br>
import package.subpackage1.moduleX<br>
<br>
To begin with it failed on the last two lines starting with 'from ...' [how do you indicate three dots followed by etc etc, which would normally be indicated by three dots!]. The traceback said 'Attempted relative import beyond toplevel package'.<br>
<br>
I did not want to investigate too deeply so I just commented those lines out, and now it runs with no errors. I even put a couple of print statements (or must I call them print functions now) into the modules being imported, and the messages do appear, so the modules are being imported.<br>
<br>
HTH<br>
<br>
Frank Millman<br><font color="#888888">
<br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>