Install m2crypto on a virtualenv without system packages
Asked Answered
G

5

18

I have created a virtual environment without the system packages with python's virtualenv in Ubuntu and installed m2crypto, but when I execute a shell and I try to import M2Crypto i get the following error:

ImportError: /home/imediava/.virtualenvs/myenv/local/lib/python2.7/site-          
packages/M2Crypto/__m2crypto.so: undefined symbol: SSLv2_method

From outside the environment I run into the same problem unless from ubuntu I install python-m2crypto with apt-get. I know that I could create the environment with the system packages but I would prefer not to do it.

Is there anyway that I could create a virtual environment without the system packages and then install m2crypto with pip without running into the SSLv2_method?

Galileo answered 11/5, 2012 at 7:35 Comment(0)
D
15

You can install this lib in your global environment and then just copy from your global site-packages to virtualenv.

Destined answered 11/5, 2012 at 8:18 Comment(4)
Thanks, I don't have my ubuntu right now but I'll try it later. Is it that simple to do? Don't you think there would be other problems?Galileo
Thanks, it did work! Now I guess is up to the guys either from ubuntu or from m2crypto to figure out why the pypi version doesn't work for ubuntu.Galileo
Thanks. I copied M2Crypto from ''dist-packages'' successfully, e.g.: from: /usr/lib/python2.7/dist-packages/M2Crypto to: ~/.virtualenvs/XXX/lib/python2.7/site-packages/Cognac
Refer to https://mcmap.net/q/551266/-ubuntu-and-undefined-symbol-for-sslv2_method. Also, instead of copying the entire directory, remember you can just symlink: ln -s /usr/lib/python2.7/dist-packages/M2Crypto ~/virtualenvs/XXX/lib/python2.7/site-packages/M2CryptoOney
S
31

There seems to be a regression bug from an earlier version of M2Crypto.

After placing M2Crypto's source in your virtualenv, you can try to patch it with the diff code below.

You do this by downloading the source code, untar it via: tar -xzf M2Crypto-0.21.1.tar.gz

This should create the directory M2Crypto-0.21.1 which will contain the SWIG directory

In SWIG you'll find _ssl.i, which is the file to be patched. In the same directory create a file called _ssl.i.patch for example using the nano editor and paste the complete diff code listed below into it.

Next issue the patch _ssl.i _ssl.i.patch command to merge the patch into the code. (Afterwards you may remove the patch file if you want.)

Finally issue the commands:

python setup.py build

followed by:

python setup.py install

to install manually.

diff code:

--- SWIG/_ssl.i 2011-01-15 20:10:06.000000000 +0100
+++ SWIG/_ssl.i 2012-06-17 17:39:05.292769292 +0200
@@ -48,8 +48,10 @@
 %rename(ssl_get_alert_desc_v) SSL_alert_desc_string_long;
 extern const char *SSL_alert_desc_string_long(int);

+#ifndef OPENSSL_NO_SSL2
 %rename(sslv2_method) SSLv2_method;
 extern SSL_METHOD *SSLv2_method(void);
+#endif
 %rename(sslv3_method) SSLv3_method;
 extern SSL_METHOD *SSLv3_method(void);
 %rename(sslv23_method) SSLv23_method;
Syllepsis answered 17/6, 2012 at 15:55 Comment(2)
There are several M2Crypto forks on Github meanwhile; I added mine to have this excellent patch (github.com/tobiasherp/M2Crypto).Sauternes
@bosse-klykken Could you please contact me either commenting on gitlab.com/m2crypto/m2crypto/commit/… or via email (mcepl at redhat dot com), so that I can acknowledge you as an author of this patch, please? Thank you.Batt
D
15

You can install this lib in your global environment and then just copy from your global site-packages to virtualenv.

Destined answered 11/5, 2012 at 8:18 Comment(4)
Thanks, I don't have my ubuntu right now but I'll try it later. Is it that simple to do? Don't you think there would be other problems?Galileo
Thanks, it did work! Now I guess is up to the guys either from ubuntu or from m2crypto to figure out why the pypi version doesn't work for ubuntu.Galileo
Thanks. I copied M2Crypto from ''dist-packages'' successfully, e.g.: from: /usr/lib/python2.7/dist-packages/M2Crypto to: ~/.virtualenvs/XXX/lib/python2.7/site-packages/Cognac
Refer to https://mcmap.net/q/551266/-ubuntu-and-undefined-symbol-for-sslv2_method. Also, instead of copying the entire directory, remember you can just symlink: ln -s /usr/lib/python2.7/dist-packages/M2Crypto ~/virtualenvs/XXX/lib/python2.7/site-packages/M2CryptoOney
W
5

M2Crypto 0.22.3 (the current version in pypi) fixes this problem, so the simplest solution is now simply:

pip install --upgrade M2Crypto

M2Crypto 0.22.3 has been released from martinpaljak's github repository, rather than from the original M2Crypto repository.

Weidman answered 11/9, 2014 at 12:53 Comment(1)
Easiest solution, should be at the topTimeworn
S
2

I had the same problem with the current release (M2Crypto-0.22.5). The latest RC build worked for me.

pip install M2Crypto==0.22.6rc4
Schizogenesis answered 30/12, 2015 at 2:49 Comment(0)
P
0

There is a patch slated for 0.26.1.

In the meantime, you can clone the repo, apply the patch, and install from source.

git clone https://gitlab.com/m2crypto/m2crypto.git
(
    cd m2crypto
    git checkout 0.25.1
    curl 'https://gitlab.com/m2crypto/m2crypto/merge_requests/117.diff' | git apply -v
)
pip install -U m2crypto
Provincial answered 3/3, 2017 at 2:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.