在我的python 3.7 + Django 2.2中,我需要连接到外部SQL Server。它不是Django的主数据库(保留在Postgres中(。我只需要对视图进行一些查询。
我在 Debian 9 上,我试图安装软件包以添加 sql 服务器连接,但我在谷歌上找不到有关 Debian 软件包安装的指南。
我尝试安装:
pip install pyodbc
pip install django-mssql-backend
但是编译失败了。我认为我缺少一些系统库。
更新 1
apt-get install unixodbc-dev
pip install pyodbc
pip install django-mssql-backend
这解决了库安装问题。现在我在尝试连接到数据库时遇到问题:
Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
谢谢。
您缺少允许unixodbc
连接到 SQL Server 的基础驱动程序。您可以在此处找到安装Microsoft ODBC 驱动程序的说明。
Debian 的简短版本,来自以下链接:
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Debian 10
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev
# optional: kerberos library for debian-slim distributions
sudo apt-get install libgssapi-krb5-2
祝你好运!