2014-09-21 181 views
2

朋友你好错误消息

在我的信息学研究我运行这个程序,遇到一个错误,而通过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 

该项目工程,同时运行良好

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

这是什么错误:当地一所大学的计算机上,但后来也有一些是在导入模块时,在通过SSH连接发生了什么? 有没有解决方案?

+0

原来自己可以指定由包括路径,当我运行程序要使用的Python或我可以使用[shebang行](http://stackoverflow.com/questions/15587877/run-a-python-脚本的终端内,而无需最Python的命令/ 15588070#15588070) – vardaasen 2015-10-01 00:54:41

回答

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脚本。