Google Colab上的Pyodbc [英] pyodbc on google colab
本文介绍了Google Colab上的Pyodbc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用pyodbc连接到我在google colab上的SQL Server.但是,它告诉我找不到驱动程序.
I am trying to connect to my SQL server on google colab by using pyodbc. However, it tells me that I cannot find the driver.
安装软件包的代码(我用x代替了IP,端口和密码)
Code to install packages (I replaced IP, port and password with x)
``` !sudo apt-get install unixodbc-dev
!pip install pyodbc
!pip install chart_studio ```
``` import pyodbc
conn = pyodbc.connect(DRIVER = '{ODBC Driver 17 for SQL Server}',
SERVER = 'xxx.xxx.x.xx, xxxx',
DATABASE = 'Database',
UID = 'sa',
PWD = 'xxxxxx')
cursor = conn.cursor()
```
我收到此错误:
```---------------------------------------------------------------------------
Error Traceback (most recent call last)
<ipython-input-12-3e54dc10e278> in <module>()
3 DATABASE = 'Database_PIL',
4 UID = 'sa',
----> 5 PWD = 'mbdxwko2')
6
7 cursor = conn.cursor()
Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
```
您对如何使其工作有任何建议吗?
Do you have any suggestion how to make it work?
谢谢!
推荐答案
我遇到了同样的问题,但最终发现直接从Microsoft安装ODBC软件包可以解决该问题.在colab中作为一个批处理运行以下代码.
I had the same problem, but finally figured out that installing the ODBC package direct from microsoft could solve it. Run the following code as a single batch in colab.
%%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
这篇关于Google Colab上的Pyodbc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文