Search code examples
pythonpython-2.7m2crypto

Python 2.7 and M2Crypto - ImportError


I am using Python 2.7.10 and have installed M2Crypto.

Importing the library like this:

from M2Crypto import RSA

but when running the python script I get this error:

ImportError: dlopen(/Users/shuma/Desktop/Projects/adastocks/vir_test/vir_test/lib/python2.7/site-packages/M2Crypto/_m2crypto.so, 2): Symbol not found: _ASN1_TIME_set_string
  Referenced from: /Users/shuma/Desktop/Projects/adastocks/vir_test/vir_test/lib/python2.7/site-packages/M2Crypto/_m2crypto.so
  Expected in: flat namespace

I am using MacOSX 10.11.5 and I tried installing with brew. But I still get the same error.


Solution

  • Solution

    This seems to work with newest m2crypto 0.22.5. I also tested it once with m2crypto 0.22.3 and seems also to work. The OpenSSL version here is 1.0.2d:

    Finally installing m2crypto on El Capitan in my Bash. It is a long command but it changes SWIG and clang environment variables only during pip install so that m2crypto will get all OpenSSL requirements, and because I am using a virtual python environment I have to clear the dir cache.

    env LDFLAGS="-L$(brew --prefix openssl)/lib" \
        CFLAGS="-I$(brew --prefix openssl)/include" \
        SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include" \
    pip install m2crypto --no-cache-dir