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.
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.
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
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.