在 19.10 上安装 unixodbc

在 19.10 上安装 unixodbc

我正在尝试使用 pyodbc 连接到 Python 中的 MSSQL 数据库。我已按照说明安装了 MS 驱动程序这里使用 19.04 版本。当尝试通过 pip 安装 pyodbc 时,我得到了sql.h: No such file or directory。谷歌搜索告诉我我需要安装unixodbcunixodbc-dev,但是当我尝试这样做时,我收到以下消息:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 unixodbc : Depends: odbcinst1debian2 (>= 2.3.7) but it is not going to be installed
            Depends: libodbc1 (>= 2.3.7) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

运行 apt autoclean、apt install -f 等没有任何反应。

答案1

看来 19.10 上的 ODBC 驱动程序附带的 unixODBC 存在问题(具体来说,multiarch-support由于某种原因,驱动程序附带的 unixODBC 的依赖项之一依赖于该依赖项,而该依赖项在所有其他 Ubuntu 上都存在,但在 19.10 上不存在)

为了解决这个问题,你可以从http://www.unixodbc.org/(参见右侧的下载按钮)并按照说明手动安装。或者通过执行以下操作安装 Ubuntu repo 中的默认 unixODBC:

#delete the package info, so that apt doesn't try to use that version of unixODBC
sudo rm /etc/apt/sources.list.d/mssql-release.list

#install the default one
sudo apt install unixodbc

#re-add the package and install the driver
sudo su
curl https://packages.microsoft.com/config/ubuntu/19.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt install msodbcsql17

相关内容