你好 friend
在我的信息学研究中,我正在运行这个程序并在通过 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: cannot open shared object file: No such file or directory
这是什么错误? 有解决办法吗?
请您参考如下方法:
启动 Python 脚本时,远程计算机上的环境设置不正确。
远程计算机上的 numpy 已使用 Intel 编译器编译,因此它在运行时需要 libifport.so.5 库。该库位于非标准目录中;不是 /lib 或 /usr/lib 或 usr/lib64 等,而是英特尔编译器安装目录的子目录,通常是 /选择/英特尔。
首先,尝试使用 module available 命令。如果它返回程序列表,则识别与 Intel 编译器对应的模块并使用 module load 加载它。
如果该命令失败,您将需要找到 libifport.so.5 的确切路径。尝试 locate libifport.so.5,或 find/opt -name libifport.so.5 并记下 libifport.so.5 所在目录的路径 驻留。然后运行
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_of_dir_with_libifort.so.5
然后运行您的 Python 脚本。
