ctypes在/ sw / lib中找不到fink安装的库 [英] ctypes doesn't find fink-installed libraries in /sw/lib

查看:101
本文介绍了ctypes在/ sw / lib中找不到fink安装的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ctypes 找不到通过fink安装的库,这些库位于 / sw / lib / 下,除非我没有明确地提供了到库的完整路径

ctypes isn't finding libraries installed via fink, which live under /sw/lib/, unless I explicitly give the full path to the libraries

>>> import ctypes
>>> ctypes.CDLL('libgoffice-0.8.dylib')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/sw/lib/python2.7/ctypes/__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libgoffice-0.8.dylib, 6): image not found
>>> ctypes.CDLL('/sw/lib/libgoffice-0.8.dylib')
<CDLL '/sw/lib/libgoffice-0.8.dylib', handle 336500 at 2b10b0>
>>>

使用 gcc 对这些库进行编译, 工作良好;他们总是被发现。为什么 ctypes 找不到这些库,我该怎么做才能找到它们?

Compilation against these libraries with gcc, however, works fine; they are always found. Why isn't ctypes locating these libraries, and what can I do to make it locate them?

这是在OS X 10.6.8上,在 /sw/bin/python2.7 下使用芬克安装的Python 2.7。

This is on OS X 10.6.8 with fink-installed Python 2.7 under /sw/bin/python2.7.

推荐答案

问题似乎是fink从未设置 LD_LIBRARY_PATH 变量。 ctypes 使用 dlopen()不会在 / sw / lib 默认情况下。在 dlopen 手册页中:

The problem seems to be that fink never sets the LD_LIBRARY_PATH variable. ctypes uses dlopen() which will not search in /sw/lib by default. From the dlopen man page:


dlopen()搜索兼容的Mach-目录中的O文件由一组环境变量和进程的当前工作
目录指定。设置后,环境变量必须包含一个冒号分隔的
目录路径列表,该列表可以是绝对的,也可以是相对于
当前工作目录的相对目录。环境变量是LD_LIBRARY_PATH,
DYLD_LIBRARY_PATH和DYLD_FALLBACK_LIBRARY_PATH。前两个变量
没有默认值。 DYLD_FALL-
BACK_LIBRARY_PATH的默认值为$ HOME / lib; / usr / local / lib; / usr / lib。 dlopen()
按照
列出的顺序搜索环境变量中指定的目录。

dlopen() searches for a compatible Mach-O file in the directories speci- fied by a set of environment variables and the process's current working directory. When set, the environment variables must contain a colon-sep- arated list of directory paths, which can be absolute or relative to the current working directory. The environment variables are LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and DYLD_FALLBACK_LIBRARY_PATH. The first two vari- ables have no default value. The default value of DYLD_FALL- BACK_LIBRARY_PATH is $HOME/lib;/usr/local/lib;/usr/lib. dlopen() searches the directories specified in the environment variables in the order they are listed.

因此解决方案似乎是放在您的 .profile .bash_profile .bashrc中

So the solution seems to be to put in your .profile, .bash_profile, or .bashrc

export LD_LIBRARY_PATH=/sw/lib:"${LD_LIBRARY_PATH}"

似乎fink还在 / sw / lib ,例如 / sw / lib / mysql 。在这些情况下,您还必须显式包括这些内容,因为 dlopen()似乎不会递归搜索 LD_LIBRARY_PATH中的路径。 。对于MySQL,您需要在路径中添加:

It also seems that fink installs some libraries in subdirectories under /sw/lib, such as /sw/lib/mysql. In these cases, you will have to explicitly include those, as well, because it seems like the dlopen() does not recursively search the paths in LD_LIBRARY_PATH. In the case of MySQL, you would need to add that in the path:

export LD_LIBRARY_PATH=/sw/lib:/sw/lib/mysql:"${LD_LIBRARY_PATH}"

这篇关于ctypes在/ sw / lib中找不到fink安装的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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