在Mac上安装PyoDBC和UnixODBC

发布于 2025-01-17 13:33:12 字数 770 浏览 4 评论 0原文

我已经看过 pypyodbc:pypyodbc:pypyodbc:pypyodbc:无法打开lib“ freetds”:未找到文件”)试图连接到sql server 的错误,但是。现在将东西放在不同的

 connection = pyodbc.connect(connection_string)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (0) (SQLDriverConnect)")

地方 显然是错误的,因为libtdsodbc在/opt/homebrew/lib

我尝试编辑odbcinst.ini,但我不确定应该在哪里生活。 t一个在 /etc中,或a /etc /unixoDBC目录...当我创建一个时,似乎不读取,因为它仍然抱怨 /usr /usr /local /lib ...

eta:这是在新的MacBook上,在其中一种新的M1芯片上。

I've seen Pypyodbc: Can't open lib 'FreeTDS' : file not found") error when trying to connect to SQL server, but. that's 7 years old, and doesn't seem to be working for me, possibly because brew appears to be putting things in different places now?

I've used brew to install unixodbc, it's in /opt/homebrew/Cellar.

When I do pip install pyodbc, it appears to work, but I get:

 connection = pyodbc.connect(connection_string)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (0) (SQLDriverConnect)")

which is obviously wrong, because libtdsodbc is in /opt/homebrew/lib

I tried editing odbcinst.ini, but I'm not sure where that's supposed to live. There wasn't one in /etc, or a /etc/unixODBC directory... and when I create either one, the don't seem to be read, because it still complains about /usr/local/lib...

ETA: This is on a new Macbook, so on one of the new M1 chips.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我的影子我的梦 2025-01-24 13:33:12

注意:这是一个糟糕的答案,希望能吸引一个好的答案,但从技术上来说它似乎是有效的。

Homebrew for M1 将所有内容安装在 /opt/homebrew 中。其他一切都需要在 /usr/local 中。在新计算机上,/usr/local/lib 甚至不存在。所以我做了

sudo ln -s /opt/homebrew/lib /usr/local/lib

这非常糟糕,我知道但这是我目前想出的解决这个问题的唯一方法。也许有什么东西没有赶上M1?我不知道。

Note: This is a BAD answer in the hopes of attracting a good one, but it technically seems to be working.

Homebrew for M1 installs everything in /opt/homebrew. Everything else expects things in /usr/local. On a new computer, /usr/local/lib didn't even exist. So I did

sudo ln -s /opt/homebrew/lib /usr/local/lib

THIS IS VERY BAD AND I KNOW IT But it's the only way I've figured out currently to deal with the problem. Maybe something hasn't caught up to M1? I'm not sure.

花落人断肠 2025-01-24 13:33:12

更好的解决方案:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/homebrew/lib

BETTER solution:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/homebrew/lib
幸福不弃 2025-01-24 13:33:12

有一个拉取请求已经被 pyodbc 维护者忽略了 13 个月:https: //github.com/mkleehammer/pyodbc/pull/870

您可以使用此命令安装分叉版本(可能需要卸载以前的版本或添加额外的参数来强制重新安装)

python3 -m pip install git+git://github.com/Aloisius/pyodbc.git@m1-homebrew

There is a pull request that has been pretty much ignored for 13 months now by the pyodbc maintainer: https://github.com/mkleehammer/pyodbc/pull/870

You can install the forked version with this command (might need to uninstall the previous version or add extra arguments to force reinstall)

python3 -m pip install git+git://github.com/Aloisius/pyodbc.git@m1-homebrew
陪你搞怪i 2025-01-24 13:33:12

因此,Unix ODBC 将其 ODBC 驱动程序移至 /usr/lib/libiodbcinst.2.dylib。参见:https://packages.debian.org/sid/libodbcinst2

打开ODBC驱动配置文件。添加以下行或类似内容,具体取决于您的 ODBC 安装位置:

ODBCInstLib=libiodbcinst.2.dylib

这可确保 ODBC 驱动程序使用正确的 iODBC 库 (/usr/lib/libiodbcinst.2.dylib) 。

您的驱动程序配置应如下所示:

[Driver]
ErrorMessagesPath=/Library/simba/spark/ErrorMessages/
LogLevel=0
LogPath=
SwapFilePath=/tmp
ODBCInstLib=libiodbcinst.2.dylib

失败此安装 unix ODBC 手动安装到您想要的任何位置并指向那里!

So Unix ODBC had its ODBC drivers moved to /usr/lib/libiodbcinst.2.dylib. See: https://packages.debian.org/sid/libodbcinst2

Open the ODBC driver configuration file. Add the following line or similar depending where your ODBC installation is at:

ODBCInstLib=libiodbcinst.2.dylib

This ensures the ODBC driver uses the correct iODBC library (/usr/lib/libiodbcinst.2.dylib).

Your driver configuration should look like this:

[Driver]
ErrorMessagesPath=/Library/simba/spark/ErrorMessages/
LogLevel=0
LogPath=
SwapFilePath=/tmp
ODBCInstLib=libiodbcinst.2.dylib

Failing this install unix ODBC manually wherever you want and point the refs there!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文