M2Crypto installation

倾然丶 夕夏残阳落幕 提交于 2020-01-17 05:54:08

问题


I am struggling to get my M2Crypto installation to work

C:\Python27>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from M2Crypto import RSA
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\M2Crypto\__init__.py", line 22, in <module>
    import __m2crypto
ImportError: No module named __m2crypto
>>>

Not really surprising as there is no __m2crypto module anywhere, but where should it be and where should I get it from?

I have installed M2Crypto from https://pypi.python.org/pypi/M2Crypto by downloading M2Crypto-master and copying the unziped M2Crypto folder to c:\Python27\lib

From M2Crypto I only need the RSA functionality so suggestions involving alternatives to M2Crypto would also be helpful.

Any help highly appreciated


回答1:


There pretty good instruction on building M2Crypto, I've using myself, here: http://www.gooli.org/blog/building-m2crypto-on-windows/

Building M2Crypto for Windows

M2Crypto uses a tool called SWIG to help write the Python code that wraps the OpenSSL library that is written in C, so we’ll have to download and install it.

Let’s go.

  1. Download the latest SWIG Windows binaries from http://www.swig.org/download.html .
  2. Unzip and untar the SWIG package to some directory and add that directory to your PATH.
  3. Download the latest M2Crypto sources from http://chandlerproject.org/bin/view/Projects/MeTooCrypto.
  4. Unzip and untar the M2Crypto source somewhere and open a command prompt there.
  5. > python setup.py build_ext –openssl c:/openssl
  6. > python setup.py bdist_wininst

That last command will create a nice M2Crypto-0.18.win32-py2.4.exe file in the dist subdirectory which you can run to install M2Crypto in the Python site-packages directory.

To test your build, run python and do import M2Crypto. If you get an error that says ‘ImportError: DLL load failed with error code 182′, it’s because the M2Crypto library can’t find the OpenSSL DLLs. You’ll need to place the libeay32.dll and ssleay32.dll files somewhere python can find them. The directory in which your script resides is a good bet.

If you still have problems with building, I'd recently compiled M2Crypto for my needs on Windows 7 x64 - Python 2.7 You can download binary here (M2Crypto-0.22.3.win32-py2.7.exe): https://drive.google.com/file/d/0ByAiJQIq8icYOUNiZEJQQzVhdVU/view?usp=sharing

Good Luck



来源:https://stackoverflow.com/questions/30344200/m2crypto-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!