Libssl和libcrypto导致dyld错误:Library not loaded: /usr/lib/libpq.5.dylib。

18

我最近通过pip卸载了postgresql并安装了pyscopg2。

我知道涉及到libcrypto和libssl的一些技巧。

目前我已经将它们建立为符号链接:

$ ls -lah libssl.*
-rwxr-xr-x  1 root  wheel   402K Aug 28 11:06 libssl.0.9.7.dylib
-rwxr-xr-x  1 root  wheel   589K Aug 28 11:06 libssl.0.9.8.dylib
lrwxr-xr-x  1 root  wheel    55B Nov 29 23:38 libssl.1.0.0.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    55B Nov 30 02:25 libssl.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libssl.1.0.0.dylib

/usr/lib
$ ls -lah libcrypto.*
-rwxr-xr-x  1 root  wheel   2.1M Aug 28 11:06 libcrypto.0.9.7.dylib
-rwxr-xr-x  1 root  wheel   2.6M Aug 28 11:06 libcrypto.0.9.8.dylib
-r-xr-xr-x  1 root  wheel   1.6M Oct 31 22:12 libcrypto.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    58B Nov 30 02:27 libcrypto.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libcrypto.1.0.0.dylib
通过ports安装了openssl,现在运行arc diff时我遇到了臭名昭著的问题。
$ arc diff
dyld: Library not loaded: /usr/lib/libpq.5.dylib
  Referenced from: /usr/bin/php
  Reason: image not found
Trace/BPT trap: 5

在Stack Overflow上有一些答案讨论将这些库链接到postgresql安装目录。显然,这对我不起作用。

我该怎么办?


什么是arc?另外,我看到/usr/bin/php;这对我来说看起来不太像Python。如果您*卸载了postgresql,我不确定如果您安装了psycopg2pip是否会为您安装postgresql(尽管如果它没有,则应该失败)。您的系统上是否有任何libpq? - user707650
8个回答

16

结果发现 /usr/lib/libpq.5.dylib 不存在,但 /usr/lib/libpq.5.4.dylib 存在。

sudo ln -s /usr/lib/libpq.5.4.dylib /usr/lib/libpq.5.dylib

问题已解决。


5
在我的情况下,库位于 /Library/PostgreSQL/9.3/lib。为了解决这个问题,我运行了 export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib:$DYLD_LIBRARY_PATH - Pablo Marambio
1
@PabloMarambio 您的解决方案对我也起作用了。谢谢。 - Usama Ahmed
反过来对我来说...!sudo ln -s /usr/lib/libpq.5.dylib /usr/lib/libpq.5.6.dylib - Ammar Akhtar
1
对于macOS Big Sur,我会为/usr/local/lib/libpq.5.dylib创建符号链接。 - A K

14

这对我起作用了,但另一个项目出了问题,因为它需要链接 postgresql@14。相反,我首先设置了 export LDFLAGS="-L/usr/local/opt/libpq/lib",重新安装了所有的 Python 项目模块,包括 psycopg2。 - mochatiger

10

我遇到了错误

库未加载:'/usr/local/opt/postgresql/lib/libpq.5.dylib'

原因:尝试:'/usr/local/opt/postgresql/lib/libpq.5.dylib'(找不到文件),'/usr/local/lib/libpq.5.dylib'(找不到文件),'/usr/lib/libpq.5.dylib'(找不到文件)

当运行Django项目时,为了修复它,我必须卸载pip软件包:

pip uninstall psycopg2 
pip uninstall psycopg2-binary 

然后重新安装它们:

pip install psycopg2 
pip install psycopg2-binary 

这使得项目可以无误地运行。


1
使用 --no-cache-dir 选项解决了我的问题。 - YPCrumble

3

与@Pablo Marambio类似,我通过在~/.profile中添加以下行来解决此问题:

export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib:$DYLD_LIBRARY_PATH

对于Postgres.app v9.3.5.0(可能也适用于其他版本),我改为添加了以下行:

export DYLD_LIBRARY_PATH=/Applications/Postgres.app/Contents/Versions/9.3/lib:$DYLD_LIBRARY_PATH

然后,当然要运行source ~/.profile

1
我更喜欢这种导出环境变量的方式,而不是在我的系统上复制或符号链接库。 - Sam Texas
这使得我无法在命令行中运行“psql DBNAME”。正在运行Postgres.app v9.5.0.0,返回的错误信息显示“dyld: Symbol not found: __cg_jpeg_resync_to_restart”。 - Raymond26

2
为了解决这个问题,我不得不卸载postgresql然后重新安装。
$ brew uninstall postgresql

$ brew update

$ brew install postgres

这个解决方案几乎也是我的,但是由于我使用的是特定版本的postgresql,我还需要一个brew link$ brew uninstall postgresql@11 && brew update && brew install postgresql@11 && brew link --force postgresql@11 - pierroz
它对我不起作用。 - thedevd
brew link --force postgresql@11 在这里发挥了魔力。 - Marlon Abeykoon

1

我需要在postgresql 14 + brew上执行此操作。

sudo ln -s /opt/homebrew/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /opt/homebrew/opt/postgresql/lib/libpq.5.dylib

0

我在我的FastAPI项目中使用诗歌工具,为了解决这个问题,我必须这样做来修复它:

poetry remove psycopg2
poetry add psycopg2

0

它试图从符号链接 /opt/homebrew/opt/postgresql/lib/libpq.5.dylib 加载 libpq.5.dylib,但未找到文件,因此您需要更新它:

# TODO: get this from the error, after "Library not loaded:"
SYMLINK_PATH="/usr/lib/libpq.5.dylib"

# TODO: find this in your machine. The version maybe different than mine
DESTINATION_PATH="/opt/homebrew/opt/postgresql/lib/postgresql@14/libpq.5.dylib"

sudo mv $SYMLINK_PATH $SYMLINK_PATH.old
sudo ln -s $DESTINATION_PATH $SYMLINK_PATH

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接