[IronPython] Pyc and subpackages

Michael Foord fuzzyman at voidspace.org.uk
Thu Sep 18 14:25:33 CEST 2008


Hello all,

I'm experimenting with the Pyc sample and compiling packages into a 
single assembly.

It works fine for packages (great!) - but not for their *contained* 
subpackages.

When I look at the generated assembly with Reflector, the 
'DLRCachedCode' does contain the subpackage 'files' (including the 
'__init__.py') - but importing from the subpackage fails.

Is this expected or a bug?

The command line I use is:

    ipy pyc.py /out:modules /target:dll package\__init__.py 
package\module1.py package\module2.py package\subpackage\__init__.py 
package\subpackage\module1.py

The '__init__.py' are all empty and the modules each contain a single 
print statement plus a single value. My top level file (left as pure 
Python) is:

    import clr
    clr.AddReference('modules')

    import package.module1
    import package.module2
    import package.subpackage.module1

    print package.module1.value
    print package.module2.value
    print package.subpackage.module1.value

It fails on the subpackage import:

    Imported package module 1
    Imported package module 2
    Traceback (most recent call last):
      File "C:\Dev\Pyc\test.py", line 6, in C:\Dev\Pyc\test.py
    ImportError: cannot import subpackage from package

*Should* this work? It would be nice if it did - because otherwise we 
are restricted to one assembly per package, and have to add a reference 
to all these assemblies.

The way I've been doing this is with 'Assembly.LoadFile' in the 
'__init__.py' - which works but is a little 'inelegant'.

Michael

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.resolverhacks.net/
http://www.theotherdelia.co.uk/




More information about the Ironpython-users mailing list