You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行msodbcsql18与pyodbc安装脚本时遇依赖错误求助

解决msodbcsql18与odbcinst依赖安装失败问题

此前多次运行以下安装脚本均可成功部署msodbcsql18、odbcinst及pyodbc,但今日执行时出现依赖未满足错误,脚本未做修改,调整后仍报错。

执行脚本

%sh
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql18 odbcinst
pip install --upgrade pip

pip install pyodbc

当前错误输出

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   983  100   983    0     0   6081      0 --:--:-- --:--:-- --:--:--  6105
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    89  100    89    0     0    772      0 --:--:-- --:--:-- --:--:--   773
deb [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/20.04/prod focal main
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:2 https://repos.azul.com/zulu/deb stable InRelease
Get:3 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [3,632 B]
Hit:4 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:5 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:6 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 114 kB in 1s (76.3 kB/s)
Reading package lists...
W: https://repos.azul.com/zulu/deb/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: https://packages.microsoft.com/ubuntu/20.04/prod/dists/focal/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Reading package lists...
Building dependency tree...
Reading state information...
msodbcsql18 is already the newest version (18.3.3.1-1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 odbcinst : Depends: odbcinst1debian2 (>= 2.3.11-1) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Requirement already satisfied: pip in /local_disk0/.ephemeral_nfs/envs/pythonEnv-ca87f34a-e32c-410d-97d4-9cbe52da43b5/lib/python3.10/site-packages (24.0)
Requirement already satisfied: pyodbc in /databricks/python3/lib/python3.10/site-packages (4.0.32)

问题分析

从错误输出可见,当前系统为Ubuntu 22.04(Jammy),但脚本添加的是Ubuntu 20.04(Focal)的微软软件源,源版本与系统版本不匹配,导致odbcinst依赖的odbcinst1debian2包无法正常安装。同时系统已存在损坏的依赖状态。

解决方案

步骤1:修复系统依赖

首先执行命令修复已损坏的依赖关系:

sudo apt --fix-broken install -y

步骤2:替换微软源为对应系统版本

删除旧的Focal源文件,添加适配Ubuntu 22.04的源:

sudo rm /etc/apt/sources.list.d/msprod.list
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

步骤3:更新源并重新安装

更新软件源后,重新安装目标包:

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql18 odbcinst -y
pip install --upgrade pip
pip install pyodbc --upgrade

可选:处理apt-key弃用警告

若要消除apt-key弃用警告,可将微软密钥导入到trusted.gpg.d目录:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null

内容的提问来源于stack exchange,提问作者Nathanael Tom Aterado

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 06:47:03