python 引用外部 pyd, dll, so 文件

作者: 刘一二 发布时间: 2023年9月8日 浏览: 24

pyd 文件通过包名可以直接引入

如果 pyd 文件又调用了 dll 或 so 动态链接库,windows 下和 linux 下对动态链接库的引用需要特殊配置

 

windows 下

需要将 dll 文件所大的目录配置到 系统 PATH 中 

 

 

linux 下

ImportError: xxxx.so.xx: cannot open shared object file: No such file or directory

解决这个问题,需要配置环境变量:LD_LIBRARY_PATH 

 

可修改 ~/.bashrc 或 /etc/profile,  加入以下内容

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/xxx/xxx

如果是 venv 部署的,可可以编辑 [venv目录名]/bin/activate

 

官方说明:

In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes. The environment variable LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. I should note that, while LD_LIBRARY_PATH works on many Unix-like systems, it doesn't work on all; for example, this functionality is available on HP-UX but as the environment variable SHLIB_PATH, and on AIX this functionality is through the variable LIBPATH (with the same syntax, a colon-separated list).

最新文章
热门文章
导航