python - 在 Azure databricks 运行时 8.3 中安装 SQL Server ODBC 库引发错误
问题描述
我正在尝试为 SQL Server 2017 安装 ODBC 库,以使用 pyodbc Python 包连接到 SQL Server。我只从 StackOverflow 获得了这段代码。安装时出现错误。
这是我正在运行的脚本:
%sh
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -q -y install msodbcsql17
我得到这个错误:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: apt-key output should not be parsed (stdout is not a terminal)
E: This command can only be used by root.
100 983 100 983 0 0 3640 0 --:--:-- --:--:-- --:--:-- 3640
**(23) Failed writing body**
/bin/bash: line 1: /etc/apt/sources.list.d/mssql-release.list: Permission denied
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
我尝试了另一个脚本,如下所示。
%sh
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
apt-get -y install unixodbc-dev
sudo apt-get install python3-pip -y
pip3 install --upgrade pyodbc
这个也失败了,如下所示。
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: apt-key output should not be parsed (stdout is not a terminal)
E: This command can only be used by root.
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 983 100 983 0 0 1790 0 --:--:-- --:--:-- --:--:-- 1787
(23) Failed writing body
/bin/bash: line 1: /etc/apt/sources.list.d/mssql-release.list: Permission denied
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
**E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?**
sudo: no tty present and no askpass program specified
Defaulting to user installation because normal site-packages is not writeable
Collecting pyodbc
Downloading pyodbc-4.0.32.tar.gz (280 kB)
Building wheels for collected packages: pyodbc
Building wheel for pyodbc (setup.py): started
Building wheel for pyodbc (setup.py): finished with status 'done'
Created wheel for pyodbc: filename=pyodbc-4.0.32-cp38-cp38-linux_x86_64.whl size=317312 sha256=baca7539ec5fb88f940fb9ba944609c211a1c84d73d02f659c9deaa0f463b700
Stored in directory: /home/spark-fcbd5404-644a-45c3-a4b1-9a/.cache/pip/wheels/68/de/de/65a129482924e96fb701c51488b907953acf25fe623bb177b3
Successfully built pyodbc
Installing collected packages: pyodbc
Successfully installed pyodbc-4.0.32
WARNING: You are using pip version 20.2.4; however, version 21.2.4 is available.
You should consider upgrading via the '/databricks/python3/bin/python -m pip install --upgrade pip' command.
不确定如何正确安装 SQL Server ODBC 和 pyodbc。请帮忙。
解决方案
我建议您重新启动集群并尝试再次运行该命令。
我在 Databricks 运行时测试过:8.3(包括 Apache Spark 3.1.1、Scala 2.12)。
%sh
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
在 ADB 8.3 上成功安装 ODBC SQL 17 驱动程序。
推荐阅读
- java - Choosing the right list for unknown numbers
- ruby - Stuck with rdoc: Any way to add indentation to call-seq?
- python - The video at python qt webbrowser no player
- javascript - 使用 javascript 在页面之间传输表格数据
- django - How to delete label of a form in Django
- arrays - MongoDB merge int arrays in one result
- javascript - Browser Copy/Paste the components
- sql-server - SQL 代理作业在 2014 年运行正常,但不是 2017 年
- php - 我在查询的 Where 语句中有 AND 运算符,我怎么知道哪个语句没有返回
- rust - 结构内的对象需要不可变和可变引用