2
Vote

Relative import in non-package error

description

Hi,
 
I'm having trouble with relative path imports in IronPython 2.7.3.
 
I add paths to the modules in my code (via sys.path.append()) so the modules are accessible. However, one of the modules I'm trying to import contains the following relative path import statement:
 
from .lib.httplib2 import Http, ProxyInfo, socks
 
When IronPython is trying to import the modules it errors out with this stderr:
 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\duber\Shotgun\3.0.9b2\shotgun.py", line 52, in <module>
ValueError: Attempted relative import in non-package
 
As soon as I remove the relative path notation (deleting the first dot from the import statement), all runs smoothly without issues.
 
If you want to try this exact scenario out, here is an article about what is needed in order to run the Shotgun API: http://blog.duber.cz/software/calling-shotgun-api-3-0-9b2-from-ironpython-2-7-3

comments

slide_o_mix wrote Jul 9, 2012 at 12:42 PM

Can you verify if this works on CPython 2.7.3? From what I have read regarding relative imports, relative imports only work on packages. The blog post you mention shows that you are trying to import from lib\ which is a subdirectory for the shotgun api code, is there an init,py in the lib directory?

loocas wrote Jul 9, 2012 at 1:12 PM

Hi, yes, there is init.py in the lib directory.

And actually, no, it doesn't seem to be working in CPython 2.7.2 :/ I don't have any other CPython installed here, so I can't verify that on any other version.

I got prompted to report this issue here from one of my commenters, so I did. :D I don't have any experience with relative path name imports, to be honest.

slide_o_mix wrote Jul 9, 2012 at 1:26 PM

Is the init.py empty?

It was me who asked you to report the issue, I saw the info on twitter and wanted to make sure the issue was captured and figured out if possible.

loocas wrote Jul 9, 2012 at 2:01 PM

Yes, the init.py under the lib folder is empty.