Question

I have installed Python 2.7 on my windows 7 x64 system with PyCrypto 2.5 compiled and built in. In my install path of D:\Python27\Lib\site-packages\Crypto\Cipher I see DES.pyd. I have opened it with dependency walker and ensured it had initDES as its only export.

What I wanted to do was copy/paste DES.pyd out now that it's built and use it in my code. So now I have my project folder D:\project containing test.py and DES.pyd.

test.py contains the code:

import sys
sys.path.append("D:\\project\\")
import DES
print 'hi'

when running test.py, i receive the following error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import DES
SystemError: dynamic module not initialized properly</code></pre>

The purpose of this exercise is to be able to send DES.pyd and test.py to my friend without having them require to build and install pycrypto (a PITA). I fully understand my code above does absolutely nothing involving DES, the fact that it cannot import it is my main curiosity. Real code using DES will follow.

Also, if I import DES.pyd directly from the python path like from Crypto.Cipher import DES works just fine.

Thanks!

Was it helpful?

Solution

Take a look at the source code at https://github.com/dlitz/pycrypto/blob/master/src/block_template.c#L801. The module name is hard coded to Crypto.Cipher._DES. Initialization will fail if _DES.pyd is not in the Crypto.Cipher package directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top