Difference between revisions of "Multiple Python versions"

From relax wiki
Jump to navigation Jump to search
(Created a page about multiple Python versions)
(No difference)

Revision as of 16:46, 8 August 2013

On certain systems, multiple Python versions may be present. Special care must be taken in such situations when running relax or when compiling the relax C modules.


SCons

When multiple Python versions are present, the scons script used to build relax is always problematic. The reason is because the top of the script starts with:

#! /usr/bin/env python
#
# SCons - a Software Constructor
#

This means that the script will look for Python in the PATH environmental variable (in Linux, Mac OS X, and MS Windows) and use that one rather than the Python it was installed for. There are two methods to overcome this difficulty.

Modifying the sources

The first is to edit the first line of this script to point to the correct Python version. For example if the Python you wish to use is installed in the /usr/local/bin/ directory, you could change this script to:

<source lang="bash">
#! /usr/local/bin/python
#
# SCons - a Software Constructor
#

Pointing to the correct version

Alternatively, if Python and scons are in /usr/local/bin, but you see:

$ which python
/usr/bin/python
$ which scons
/usr/bin/scons

You can simply provide full paths when compiling the relax C modules:

$ cd /path/to/relax/
$ /usr/local/bin/python /usr/local/bin/scons

The last command forces /usr/local/bin/scons to use the correct Python version.


Running relax

When multiple Python versions are present, there are two ways to run relax with the correct version.

Modifying the sources

The first is to permanently modify the relax sources to use the correct Python. If you look at the top of the relax file, you will see:

#! /usr/bin/env python

# Import the relax module.
import relax

# Start relax.
relax.start(profile_flag=False)

If the wrong Python version is being used, then assuming the correct one is in /usr/local/bin/python, change that file to:

#! /usr/local/bin/python

# Import the relax module.
import relax

# Start relax.
relax.start(profile_flag=False)

This will force the correct version.


Pointing to the correct version

The alternative is to simply run relax with:

$ /usr/local/bin/python ~/bin/relax

This assumes that relax is installed in the home directory.