views:

28

answers:

2

I am trying to use IronPython under VS 2010.

I need Gzip, but there is no (that I can find) documentation to tell me how to "reference" or add a module.

Can anyone tell how to add Gzip please.

A: 
import clr
from System.IO.Compression import GZipStream

#or if your implementation is in some external assembly
clr.AddReference("<assembly-with gzip implementation>")
# from Gzip import Impl blah-blah-blah 
desco
I tried the first two lines - but I still get error saying gzip module not found
ManInMoon
desco, could you give me a bit more hand-holding on this please
ManInMoon
you use some particular Gzip implementation or just want to know if any gzip available and use it?
desco
A: 

First off, IronPython does not include the gzip module because it's not supported out of the box. You can pull a copy from the Python source tree or from http://bitbucket.org/jdhardy/ironpythonzlib/src/tip/tests/gzip.py. Put this file in the Lib folder of your IronPython installation.

Next, you need an implementation of zlib for IronPython; you probably want the 'clr4' version for .NET 4.0. Put IronPython.Zlib.dll in the DLLs folder of your IronPython installation; if the DLLs folder does not exist, just create it.

If you can't modify the IronPython install (and with VS 2010, I don't think you can), put gzip.py and IronPython.Zlib.dll in the same folder as the rest of your files, and add the following lines near the top of gzip.py, after the other import statements:

if sys.platform == 'cli':
    import clr
    clr.AddReference('IronPython.Zlib')

Either way, you should now be able to do import gzip from IronPython.

Jeff Hardy
Thank you for that full - and step by step answer. It is really useful to a newbie like me
ManInMoon
@ManInMoon You're welcome. If you're new to SO you should upvote and select an answer.
Jeff Hardy