从ssh连接时从模块numpy导入时来自python的错误消息

时间:2014-09-21 07:40:55

标签: python numpy ssh

朋友你好

在我的信息学研究中,我正在运行此程序,并在通过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

为了方便地测试这个功能,我已经在程序中包含了一个测试功能:

#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

该程序在本地大学计算机上运行时工作正常,但是在通过ssh连接时导入模块时会发生一些事情:

  

... ImportError:libifport.so.5:无法打开共享对象文件:没有这样的文件或目录

这是什么错误? 有解决方案吗?

1 个答案:

答案 0 :(得分:1)

启动Python脚本时,未正确设置远程计算机上的环境。

远程计算机上的numpy已使用英特尔编译器编译,结果是它在运行时需要libifport.so.5库。该库位于非标准目录中;不是/lib/usr/libusr/lib64等,而是英特尔编译器安装目录的子目录,通常为/opt/intel

首先,尝试module available命令。如果它返回程序列表,请标识与英特尔编译器对应的模块,并使用module load加载它。

如果该命令失败,您需要找到libifport.so.5的确切路径。请尝试locate libifport.so.5find /opt -name libifport.so.5并记下libifport.so.5所在目录的路径。然后运行

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_of_dir_with_libifort.so.5

然后运行你的Python脚本。