在运行时为ctypes更改LD_LIBRARY_PATH [英] Changing LD_LIBRARY_PATH at runtime for ctypes

查看:132
本文介绍了在运行时为ctypes更改LD_LIBRARY_PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时更新此环境变量,以便ctypes可以在任何地方加载库?我尝试了以下操作,但似乎都没有用。

How do you update this environment variable at runtime so that ctypes can load a library wherever? I've tried the following and neither seem to work.

from ctypes import *
os.environ['LD_LIBRARY_PATH'] = "/home/starlon/Projects/pyCFA635/lib"  
os.putenv('LD_LIBRARY_PATH', "/home/starlon/Projects/pyCFA635/lib")  
lib = CDLL("libevaluator.so")


推荐答案

Python正在运行,动态加载程序(ld.so.1或类似的文件)已经读取了LD_LIBRARY_PATH,此后将不会发现任何更改。因此,除非Python软件本身评估LD_LIBRARY_PATH并使用它来构建 dlopen()或可能使用的等效函数的库的可能路径名,否则请在

By the time a program such as Python is running, the dynamic loader (ld.so.1 or something similar) has already read LD_LIBRARY_PATH and won't notice any changes thereafter. So, unless the Python software itself evaluates LD_LIBRARY_PATH and uses it to build the possible path name of the library for dlopen() or an equivalent function to use, setting the variable in the script will have no effect.

鉴于您说它不起作用,因此可以假设Python没有构建并尝试所有可能的库名似乎是合情合理的。它可能仅依靠LD_LIBRARY_PATH。

Given that you say it doesn't work, it seems plausible to suppose that Python does not build and try all the possible library names; it probably relies on LD_LIBRARY_PATH alone.

这篇关于在运行时为ctypes更改LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆