pyodbc在谷歌colab上



我正试图使用pyodbc连接到谷歌colab上的SQL服务器。然而,它告诉我找不到司机。

安装软件包的代码(我用x替换了IP、端口和密码(

``` !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)")
``` 

你对如何使它发挥作用有什么建议吗?

谢谢!

我也遇到了同样的问题,但最终发现直接从微软安装ODBC包可以解决这个问题。

%%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

谢谢你们,这对我很有用:

第一块

%%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

相关内容

  • 没有找到相关文章

最新更新