无法为 ctypes 设置环境变量(python 的 c 库)
Unable to set environment variable for ctypes (c library for python)
我需要将一些第三方 c 库导入到低级模块中。我正在关注 these instructions。它说 find_library() 应该可以帮助我找到这样一个库,不包括任何库前缀和 .so 后缀。
#next 2 lines just to test
test =find_library('spcm_linux')
print(test)
#this line below is the actual code
spcmDll = cdll.LoadLibrary("libspcm_linux.so")
Returns:
None
OSError: spcm_linux.so: cannot open shared object file: No such file or directory
我的图书馆位于:
/usr/lib/gcc/x86_64-linux-gnu/libspcm_linux.so
从文档中阅读有关 find_library() 的内容,它告诉我可以设置一个环境变量来添加一个环境变量 (LD_LIBRARY_PATH)。所以在 /etc/environement 我有:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
PYTHONPATH="/home/fv/.local/lib/python3.6/site-packages"
LD_LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu"
我重新启动,尝试它仍然不起作用(同样的错误信息)。
还有 "find" 我的图书馆的其他方式吗?可以将它直接放在我的 program.py 目录中并以其他方式导入吗?
编辑:
但是,它确实找到了 libgomp.so.1
,它与我要加载的库位于完全相同的文件夹中。如果有帮助...
原来问题的根源是权利。
libspcm_linux.so
库的权限设置不正确,因此脚本没有访问权限。
然而,弹出的错误仍然是关于No such file or directory
。我认为这是因为它是一个 C 库,ctypes 试图加载它。它无法加载它(因为它没有它的权利)但是显然它不认为它适合传播错误(或者不能因为 C 代码加载方式的一些技术细节,可能)。
因此从它的角度来看,它无法加载请求的库,并告诉我 - "No such file or..." 即使这隐藏了问题的真正原因。
我需要将一些第三方 c 库导入到低级模块中。我正在关注 these instructions。它说 find_library() 应该可以帮助我找到这样一个库,不包括任何库前缀和 .so 后缀。
#next 2 lines just to test
test =find_library('spcm_linux')
print(test)
#this line below is the actual code
spcmDll = cdll.LoadLibrary("libspcm_linux.so")
Returns:
None
OSError: spcm_linux.so: cannot open shared object file: No such file or directory
我的图书馆位于:
/usr/lib/gcc/x86_64-linux-gnu/libspcm_linux.so
从文档中阅读有关 find_library() 的内容,它告诉我可以设置一个环境变量来添加一个环境变量 (LD_LIBRARY_PATH)。所以在 /etc/environement 我有:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
PYTHONPATH="/home/fv/.local/lib/python3.6/site-packages"
LD_LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu"
我重新启动,尝试它仍然不起作用(同样的错误信息)。
还有 "find" 我的图书馆的其他方式吗?可以将它直接放在我的 program.py 目录中并以其他方式导入吗?
编辑:
但是,它确实找到了 libgomp.so.1
,它与我要加载的库位于完全相同的文件夹中。如果有帮助...
原来问题的根源是权利。
libspcm_linux.so
库的权限设置不正确,因此脚本没有访问权限。
然而,弹出的错误仍然是关于No such file or directory
。我认为这是因为它是一个 C 库,ctypes 试图加载它。它无法加载它(因为它没有它的权利)但是显然它不认为它适合传播错误(或者不能因为 C 代码加载方式的一些技术细节,可能)。
因此从它的角度来看,它无法加载请求的库,并告诉我 - "No such file or..." 即使这隐藏了问题的真正原因。