2

Hello friends

In my informatics study I am running this program and encounter an error while connecting via ssh:

'''
a*x**2 + b*x + c = 0
roots(a, b, c)
returns floats when real solution, or complex when complex solution.
'''
#the code for the function
def roots(a, b, c):
    """The root(a, b, c) function solves x for a quadratic equation:
    a*x**2 + b*x + c = 0
    """
    from numpy.lib.scimath import sqrt
    x1 = (-b + sqrt((b)**2 - 4.*a*c))/(2.*a)
    x2 = (-b - sqrt((b)**2 - 4.*a*c))/(2.*a)
    return x1, x2

To easily test this function I have made a test function to include in the program:

#test functions for float and complex numbers

def test_roots_float():
    """Tests the function root(a, b, c) for floats.
    Returns True if the function works for floats.
    """
    ax1 = 0.0                                         #known solution for x1
    ax2 = -1.0                                        #known solution for x2
    x1, x2 = roots(2, 2, 0)                           #solve for known solution
    if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0:     #test
        return True
    return False
def test_roots_complex():
    """Tests the function root(a, b, c)
    for complex numbers. Returns True if the
    function works for complex solutions.
    """
    ax1 = (-0.5+0.5j)                                 #known solution for x1
    ax2 = (-0.5-0.5j)                                 #known solution for x2
    x1, x2 = roots(2, 2, 1)                           #solve for known solution
    if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0:     #test
        return True
    return False
#run
print 'Test results:'

#test run for floats
test1 = test_roots_float()
if test1:
    test1 = 'works'
print 'The function roots(a, b, c) %s for float type\
 solutions.' % test1

#test run for complex
test2 = test_roots_complex()
if test2:
    test2 = 'works'
print 'The function roots(a, b, c) %s for complex\
 type solutions.' % test2

The program works fine while run on a local university computer, but then there is something happening when importing modules while connected via ssh:

... ImportError: libifport.so.5: cannot open shared object file: No such file or directory

What is this error? And is there a solution?

vardaasen
  • 33
  • 6
  • I realise i can specify which python to use by including a path when I run the program, or I could use a [shebang line](http://stackoverflow.com/questions/15587877/run-a-python-script-in-terminal-without-the-python-command/15588070#15588070) – vardaasen Oct 01 '15 at 00:54

1 Answers1

1

The environment on the remote computer is not set correctly when you start your Python script.

The numpy on the remote computer has been compiled with the Intel compiler, with the consequence that it requires the libifport.so.5 library at run time. That library is located in a non standard directory; not /lib or /usr/lib or usr/lib64 etc, but a subdir of the Intel Compiler installation directory, often /opt/intel.

First off, try the module available command. If it returns a list of programs, identify the module corresponding to the Intel compiler and load it with module load.

If that command fails you'll need to find the exact path to libifport.so.5. Try locate libifport.so.5, or find /opt -name libifport.so.5 and note the path of the directory in which libifport.so.5 resides. Then run

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_of_dir_with_libifort.so.5

Then run your Python script.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110