tags:

views:

225

answers:

1

Can you use PyCrypto with py2exe? Can you use any arbitrary library for that matter with py2exe?

Thanks, Chris

A: 

I have yet to find anything that py2exe can't actually handle, though from time to time it has lagged developments in Python itself. (For example, for a while it had trouble with the new absolute imports stuff, though I believe that's been resolved. It also wasn't so good with eggs, but I don't know if that has been resolved.)

I don't see why you'd have any problem using it with PyCrypto either, as that package has nothing special in it compared to many others that work fine. It's a bunch of pure Python plus a handful of .pyd files, and certainly py2exe deals well with those. Here's an example, using code pulled from the PyCrypto site:

from Crypto.Cipher import DES

def main():
    obj=DES.new('abcdefgh', DES.MODE_ECB)
    plain='Thvqb ina Ebffhz vf n fcnpr nyvra.'.encode('rot13')
    ciph=obj.encrypt(plain+' ' * 6)
    print obj.decrypt(ciph)

if __name__ == '__main__':
    import sys
    if sys.argv[1:] == ['py2exe']:
        from distutils.core import setup
        import py2exe
        setup(console=[dict(script='script.py')],
            options={'py2exe': {'excludes': ['Tkinter'] }})

    else:
        main()

Save as script.py, build using script py2exe, and run with dist\script to see some output.

Peter Hansen
Would it work with m2crypto, since it's just a wrapper?
Chris
@Chris: Make a test app and find out.
Brian
@Chris, if by "just a wrapper" you mean "pure Python", then certainly it would. Py2exe doesn't have to do anything special for one generic package versus another. If a package does something exotic, it may need special handling, but a) most packages aren't exotic, and b) any popular package will have been dealt with already long before you found it.
Peter Hansen