简体   繁体   English

使用 Pyodbc 将 SQL 连接到 Google Colab 时出错

[英]Error connecting SQL to Google Colab using Pyodbc

I'm attempting to connect SQL to Colab notebook using the exact code that works perfectly when I run it in Spyder, but throws an error in Colab!我正在尝试使用在 Spyder 中运行时完美运行的确切代码将 SQL 连接到 Colab 笔记本,但在 Colab 中引发错误!

conn = pyodbc.connect(
    "Driver={SQL Server Native Client 17.0};"
    "Server=servername;"
    "Database=dbname;"
    "Trusted_Connection=yes;"
)

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 17.0' : file not found (0) (SQLDriverConnect)")

In an attempt to resolve it, I've run the following, as suggested here but to no avail.为了解决它,我按照此处的建议运行了以下命令,但无济于事。 There's precious little on the web about this issue as well. web 关于这个问题的信息也很少。

%%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
!sudo apt-get install unixodbc-dev
!pip install pyodbc
!pip install chart_studio

import pyodbc

It's been a while since this was posted, but since I had the same problem and didn't find an answer anywhere, here is what worked for me:自发布以来已经有一段时间了,但是由于我遇到了同样的问题并且在任何地方都没有找到答案,所以这对我有用:

!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

I did it in trial and error, but I hope it can help other people.我在反复试验中做到了,但我希望它可以帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM