0

I have a problem similar to this post: Install python module to non default version of python on Mac, so I am aware of those solutions, but they do not work for me.

I am installing M2Crypto on CentOS, which means I much use fedora_setup.sh build followed by fedora_setup.sh install in order to install on my architecture.

Unfortunately, the default Python version is 2.6, but I use 2.7. How do I execute the build and install commands so that they build and install to Python2.7 site-packages? Is there a simple command I don't know? I've been searching around here: http://docs.python.org/2/install/ in the Python Docs, but I don't see anything about .sh scripts?

Community
  • 1
  • 1
fildred13
  • 2,280
  • 8
  • 28
  • 52

2 Answers2

0

You should run your scripts in a virtualenv created for your app's environment. This creates an isolated environment that uses the Python interpreter you created the virtualenv with, but with its own set of libraries.

# create the virtualenv folder: M2Crypto-venv
python2.7 virtualenv.py --distribute M2Crypto-venv

# activate the virtualenv, changing environment variables to use its Python interpreter
. M2Crypto-venv/bin/activate

# see how the current python has changed
which python        # should be M2Crypto-venv/bin/python
python --version    # should be 2.7

# after activating, run your install scripts

If you're using mod_wsgi or something similar to serve content, you'll want to modify your WSGI file to activate the virtualenv before doing anything else (adapted from mod_wsgi instructions):

import os.path

virtualenv_path = '/path/to/M2Crypto-venv'
activate_this = os.path.join(virtualenv_path, 'bin/activate_this.py')
execfile(activate_this, dict(__file__ = activate_this))

# rest of the WSGI file...
  • Will the rest of my project be able to access the resources installed in the virtualenv? IF Django can't talk to M2Crypto, then it defeats the purpose for me. Will I be able to just add the virtualenv to the Python Path or something? – fildred13 Jun 24 '13 at 03:51
  • You should install Django and the other project components in the virtualenv as well. After you've activated, the virtualenv `pip` can do that for you. – SteelPangolin Jun 24 '13 at 03:59
  • If you're using mod_wsgi or something similar to serve content, you'll want to modify your WSGI file to activate the virtualenv before doing anything else (config added to original post) – SteelPangolin Jun 24 '13 at 04:01
  • Hrm, I already have the site all but completely setup, so this wouldn't be ideal. If there is no other solution, I suppose I can do all the work to make this happen, but I'd prefer to just install to the "real" python2.7 if I can. – fildred13 Jun 24 '13 at 04:04
  • @fildred13: virtualenvs take a few extra minutes to set up, but are *wonderful* for isolating different apps with different dependencies on the same server. We use this capability frequently where I work - not all apps run on the same version of Django, for example. – SteelPangolin Jun 24 '13 at 04:06
  • Okay, I'll do some reading and see if it is a good solution for me. But M2Crypto works in Python2.7, as it is functioning on my development server now. So if it isn't a dependency problem, why should I use a dependency solution? – fildred13 Jun 24 '13 at 04:07
0

This was an incredibly difficult answer to come by, but the support team at Webfaction where I am hosted were spectacular in assisting me. Directly from the support I was given:

First build swig,

wget http://prdownloads.sourceforge.net/swig/swig-2.0.8.tar.gz
tar -xf swig-2.0.8.tar.gz 
cd swig-2.0.8
./configure --prefix=$HOME
make
make install

Than get m2crypto,

svn checkout http://svn.osafoundation.org/m2crypto/tags/0.21/ m2crypto-0.21
cd m2crypto-0.21/

Edit fedora_setup.sh from this

SWIG_FEATURES=-cpperraswarn python setup.py $*

to this,

SWIG_FEATURES=-cpperraswarn python2.7 setup.py $*

Then build, then install,

./fedora_setup.sh build
./fedora_setup.sh install --prefix=$HOME

[me@web342 lib]$ python2.7
Python 2.7.5 (default, May 16 2013, 20:16:09) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import M2Crypto
>>> print M2Crypto
<module 'M2Crypto' from '/home/me/lib/python2.7/site-packages/M2Crypto-0.21-py2.7-linux-x86_64.egg/M2Crypto/__init__.pyc'>

Obviously, substitute your own details throughout. Hope this helps the next guy trying to install M2Crytpo using fedora_setup to a non-default python version.

fildred13
  • 2,280
  • 8
  • 28
  • 52