如何强制Python使用特定的库(psycopg2和osx)? [英] How can I force Python to use specific libraries ( psycopg2 & osx )?

查看:99
本文介绍了如何强制Python使用特定的库(psycopg2和osx)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我弄清楚了当前许多osx安装的根本问题(例如 http://psycopg.lighthouseapp.com/projects/62710/tickets/111-library-not-loaded-libssl100dylib python pip安装psycopg2安装错误

I figured out what the underlying problem is with many of the current osx installations ( such as http://psycopg.lighthouseapp.com/projects/62710/tickets/111-library-not-loaded-libssl100dylib and python pip install psycopg2 install error )

很多人使用来自EnterpriseDB的PostgreSQL安装程序;可能是因为它是 http://www.postgresql.org/download/macosx/

A lot of people use the PostgreSQL installer from EnterpriseDB ; probably because it's the first option in http://www.postgresql.org/download/macosx/

如果安装了该程序,它将所有需要的二进制文件和库安装到专用版本空间中。

If you install with that, it installs all the needed binaries and libraries into it's private versioned space...

ie

/Library/PostgreSQL/9.2/bin
/Library/PostgreSQL/9.2/lib

/Library/PostgreSQL/8.4.5/bin
/Library/PostgreSQL/8.4.5/lib

如果我运行pg_config(指向/ Library / PostgreSQL / v / bin / pg_config),它将显示正确的信息

If I run pg_config ( which points to the /Library/PostgreSQL/v/bin/pg_config ) it shoes the right info

LIBDIR = /Library/PostgreSQL/9.2/lib

但是导入psycopg2的所有错误似乎都表明psycopg2试图从/ usr / local / lib加载,而不是从其编译的lib(或者应该是期望的)加载。

However, all the errors from importing psycopg2 seem to show that psycopg2 is trying to load out of /usr/local/lib and not the lib that it was compiled against ( or should be expecting )

我尝试使用环境变量(LD_LIBRARY_PATH,LD_PRELOAD),但是无法似乎使这项工作。除非(正确的)文件是/ usr / local / lib,否则psycopg2不想导入。

I tried using environment vars ( LD_LIBRARY_PATH , LD_PRELOAD ) but can't seem to make this work. Unless the (correct) files are /usr/local/lib , psycopg2 doesn't want to import.

我不喜欢其他人在这里提到的解决方案重写或链接这些文件;有一种方法可以强制Python / psycopg2使用预期的文件路径。

I don't like the solution that others have mentioned here to rewrite or link these files; there's got to be a way to force Python / psycopg2 to use the intended filepaths.

推荐答案

您的问题是您使用的是错误的环境变量。

Your problem is that you're using the wrong environment variables.

LD_LIBRARY_PATH 由linux / glibc,FreeBSD和某些链接加载程序使用其他* nix平台,但对于Mac OS X链接加载器,不是。有关<$ c $,请参见联机帮助页c> dyld 表示的存在

LD_LIBRARY_PATH is used by the link-loaders for linux/glibc, FreeBSD, and some other *nix platforms, but not for the Mac OS X link-loader. See the manpage for dyld for what does exist.

明显的替代物是 DYLD_LIBRARY_PATH 。但是,这可能不是您想要的(出于相同的基本原因, LD_LIBRARY_PATH 通常是Linux上想要的,但是细节有所不同)。相反,您可能需要 DYLD_FALLBACK_LIBRARY_PATH 。简而言之,这样做是改变 fallback 搜索路径(通常〜/ lib:/ usr / local / lib:/ lib:/ usr / lib )用于主要搜索路径中找不到的库,而不是更改主要搜索路径,因此您可以提供缺少的库,而不会阻止实际存在的库。 (尝试以任何一种方式运行任何X11应用程序,以非常简单地演示它们之间的区别。)该联机帮助页解释了详细信息。

The obvious replacement is DYLD_LIBRARY_PATH. However, this is probably not what you want (for really the same basic reasons LD_LIBRARY_PATH usually what you want on linux, but the details are different). Instead, you probably want DYLD_FALLBACK_LIBRARY_PATH. Briefly, what this does is change the fallback search paths (normally ~/lib:/usr/local/lib:/lib:/usr/lib) used for libraries not found in the primary search paths, instead of changing the primary search paths, so you can provide missing libraries, without blocking libraries that actually exist. (Try running, e.g., any X11 app each way for a very simple demonstration of the difference.) The manpage explains the details.

(顺便说一句,如果您想知道OS X的链接加载器有什么特别之处,以至于他们认为需要使用不同的环境变量,这主要是关于框架和版本控制,尽管您可以嵌入的自定义魔术路径也很重要。NeXT或Apple的人大概会认为使用相同的名字来表示80%相同但20%不同的东西比具有误导性要大得多。)

(By the way, if you're wondering what's so special about OS X's link-loader that they felt the need to use different environment variables, it's mainly about frameworks and versioning, although the custom magic paths you can embed are also relevant. Someone at NeXT or Apple presumably felt it would be more misleading than helpful to use the same names to mean something 80% the same but 20% different…)

这篇关于如何强制Python使用特定的库(psycopg2和osx)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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