2014-09-21 180 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腳本。