1

I need to use M2Crypto in my code. I downloaded the library as zip file from: https://github.com/martinpaljak/M2Crypto I unzipped the file. Inside the zipped file, I found folder named: M2Crypto, I copied it, and paste it in the same directory where my code .py file resides.

I added this line

from M2Crypto import RSA, X509

But I am getting this error:

import __m2crypto ImportError: No module named '__m2crypto'

Can you help me with the right way to import external library to python code? I am using windows system and I type the code using notepad++ so please, consider this in the answer.

EDIT: I use python 3.4

Pedro del Sol
  • 2,840
  • 9
  • 39
  • 52
user2192774
  • 3,807
  • 17
  • 47
  • 62
  • Most likely - it has got some 'c' extensions that were not compiled. simply unzipping and copying python won't help. You need to do - python setup.py install - that would build any 'c' extensions and put it in correct path. For that you'd need Dev tools installed. eg. something like gcc on linux or Visual Studio on windows. After those 'c' extensions get built, you'd see something like - __m2crypto.so generated, then you should be good. – gabhijit Jun 14 '15 at 02:18

2 Answers2

0

Unfortunately, simply copying some files won't work. Part of this module is an extension written in C (the files in the SWIG directory) that needs to be compiled into a shared library called __m2crypto.

The installation procedure is covered in the INSTALL file.

Fair warning: compared to *BSD, Linux and OS-X, building open source software on ms-windows is a really painful experience. Out-of-the-box, ms-windows lacks the development infrastructure and a lot of basic software that the aforementioned systems provide and most open-source software expects.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
0

To install M2Crypto in windows, download the 2 files (x64 or x86 version depends on your system) from this link: https://github.com/dsoprea/M2CryptoWindows. Unzip the 2 files in the C: directory. Then, type this command:

C:\Python27\Scripts>pip install --egg M2CryptoWin64

Note: In the command, I used M2CryptoWin64 because this is what I installed. You might need to change this if you downloaded the x86 version.

user2192774
  • 3,807
  • 17
  • 47
  • 62