Difference between revisions of "Multiple Python versions"

From relax wiki
Jump to navigation Jump to search
m (removed Category:Software using HotCat)
 
(6 intermediate revisions by 2 users not shown)
Line 12: Line 12:
 
</source>
 
</source>
  
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, either by modifying the SCons source file or by pointing to the correct Python and SCons versions.
+
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 version it was installed for.  This is a fatal problem when multiple Python versions are present as the SCons files are installed as a site-package for the specific Python version, not for the default Python version on the PATH.  There are two methods to overcome this difficulty, either by modifying the SCons source file or by pointing to the correct Python and SCons versions.
  
  
 
=== Modifying the sources ===
 
=== 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">
+
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">
 
<source lang="bash">
 
#! /usr/local/bin/python
 
#! /usr/local/bin/python
Line 71: Line 71:
 
</source>
 
</source>
  
This will force the correct version.
+
This will force the correct version. Note that if you are using MS Windows you will need to modify the '''relax.bat''' file instead, adding the full Python path to the '''python''' command in that batch file.
 
 
  
 
=== Pointing to the correct version ===
 
=== Pointing to the correct version ===
Line 90: Line 89:
 
alias relax /usr/local/bin/python ~/bin/relax
 
alias relax /usr/local/bin/python ~/bin/relax
 
</source>
 
</source>
 +
 +
 +
= See also =
 +
 +
[[Category:Python]]

Latest revision as of 18:50, 21 October 2020

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 version it was installed for. This is a fatal problem when multiple Python versions are present as the SCons files are installed as a site-package for the specific Python version, not for the default Python version on the PATH. There are two methods to overcome this difficulty, either by modifying the SCons source file or by pointing to the correct Python and SCons versions.


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:

#! /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, either by modifying the relax sources or by pointing to the correct Python 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. Note that if you are using MS Windows you will need to modify the relax.bat file instead, adding the full Python path to the python command in that batch file.

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. This can be added as an alias to the ~/.bashrc file or equivalent:

alias relax="/usr/local/bin/python ~/bin/relax"

For csh or tcsh, modify the ~/.cshrc file as:

alias relax /usr/local/bin/python ~/bin/relax


See also