python .so共享文件没有找到

Ubuntu12.04 下使用pyev 模块,但是运行sudo python setup.py install后却提示出现以下错误:

Traceback (most recent call last):
  File "setup.py", line 59, in <module>
    check_version(libev_version(), min_libev_version, "libev")
  File "setup.py", line 50, in libev_version
    libev_dll = cdll.LoadLibrary(libev_dll_name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libev.so.4: cannot open shared object file: No such file or directory


很显然是缺少共享库文件,但是当我去/usr/local/lib下查找时,确发现有libev.so.4这个文件,那就是共享库搜索路径不对的问题,然后再去查看系统的共享库搜索路径配置,/etc/ld.so.conf, 发现里面只有一句 include /etc/ld.so.conf.d/*.conf,然后再去查看/etc/ld.so.conf.d/下的文件,发现libc.conf中已经包括了/usr/local/lib这个路径,那么问题来了,通过include包括文件的方法本应可以把/usr/local/lib这条路径包括近来的,看来是python的ctypes.cdll.LoadLibray()这里出了问题。查看python官网上ctypes模块部分,给出"On Linux, find_library() tries to run external programs(/sbin/ldconfiggcc, andobjdump) to find the library file. Itreturns the filename of the library file",这里选使用ldconfig的默认搜索路径,而ldconfig默认搜索路径是/usr,/usr/lib,和/etc/ld.so.conf中列出的路径,所以应该是把/usr/local/lib这条路径直接添加到/etc/ld.so.conf的新行中,然后sudo ldconfig使之生效,这样就确保了ctypes相关方法可以找到共享库的正确的搜索路径。然后再sudo python setup.py install就可以成功了。

猜你喜欢

转载自blog.csdn.net/nicholas_liu2017/article/details/78128706
今日推荐