Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install m2crypto on a virtualenv without system packages

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?

like image 579
txominpelu Avatar asked May 11 '12 07:05

txominpelu


People also ask

Can I install packages in virtual environment?

As long as your virtual environment is activated pip will install packages into that specific environment and you'll be able to import and use packages in your Python application.

Where is Virtualenv installed?

If you try to run virtualenv and find it isn't present, you can install it using pip. virtualenv.exe will likely now be found in your python installation directory under the Scripts subdirectory.


2 Answers

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;
like image 95
Bosse Klykken Avatar answered Sep 21 '22 18:09

Bosse Klykken


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

like image 21
Denis Avatar answered Sep 23 '22 18:09

Denis