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?

2 Answers 2

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...
Sign up to request clarification or add additional context in comments.

6 Comments

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?
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.
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)
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: 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.
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.