如何使用 unixODBC 安装 sqlite3 ODBC 驱动程序?

5 python sqlite sqlite3 odbc

根据unixODBC驱动程序页面(直接从 90 年代开始),我应该从以下位置下载 SQLite3 驱动程序:http : //www.ch-werner.de/sqliteodbc

sqliteodbc从该页面上提供的源代码构建的说明可在此处获得:http : //www.ch-werner.de/sqliteodbc/html/index.html

根据该页面,我们应该将源文件解压到一个目录中,然后运行以下命令:

1) ./configure 2) make 3)make install

但是,当我./configure在目录中运行时,出现以下错误:

configure: error: No usable SQLite header/library on this system

我该怎么办?

小智 6

为了应对configure: error: No usable SQLite header/library on this system,人们必须:

sudo apt-get install libsqlite3-dev

执行此操作后,您可能仍会收到以下错误:

configure: error: ODBC header files and/or libraries not found

在这种情况下,请执行以下操作:

sudo apt-get install unixodbc-dev unixodbc-bin unixodbc

您可能已经拥有其中列出的一些软件包,但如果您收到错误,则说明您缺少unixodbc-dev.

好吧,现在你应该:

1)./configure && make没有问题

2)而不是make install查看此处的说明来了解所有信息checkinstall我通过获取源代码安装了一个程序,然后运行“sudo make install”;如何让 apt-get 了解它?

现在,进一步阅读为sqliteodbc驱动程序提供的[说明],我们必须:

odbcinst.ini1)正确设置

在编辑器中打开odbcinst.ini(您可能需要超级用户能力,并且您需要知道文件在哪里 - 通常它在 /etc 中,所以我们可以这样做:)sudo gedit /etc/odbcinst.ini,然后添加以下内容:

[SQLite3]
Description=SQLite ODBC Driver
Driver=/usr/local/lib/libsqlite3odbc.so
Setup=/usr/local/lib/libsqlite3odbc.so
Threading=4
Run Code Online (Sandbox Code Playgroud)

Description使用您想要的任何字符串进行设置,但请确保Driver具有安装驱动程序所提供的Setup正确路径。为了找出/确认提供了哪些文件:要么打开并检查您拥有哪些文件。例如,根据说明中的示例,您应该指向,但我只有。如果两者都有,您可以输入两个条目,如下所示:*.sosqliteodbc*.sogrep/usr/local/lib/*.so/usr/local/lib/libsqliteodbc.so/usr/local/lib/libsqlite3odbc.so

[SQLite3]
Description=SQLite ODBC Driver
Driver=/usr/local/lib/libsqlite3odbc.so
Setup=/usr/local/lib/libsqlite3odbc.so
Threading=2

[SQLite]
Description=SQLite ODBC Driver
Driver=/usr/local/lib/libsqliteodbc.so
Setup=/usr/local/lib/libsqliteodbc.so
Threading=2
Run Code Online (Sandbox Code Playgroud)

另外,请确保为线程选择一些合适的值。例如,如果您有 8 个核心,也许Threading=4会有意义。

为了执行第 2 步,我将进行以下设置:

[MYGOOFYSQLITE3DRIVERTAG]
Description=SQLite ODBC Driver
Driver=/usr/local/lib/libsqlite3odbc.so
Setup=/usr/local/lib/libsqlite3odbc.so
Threading=2
Run Code Online (Sandbox Code Playgroud)

2) 可选:设置 DNS ~/.odbc.ini--- 只需按照说明操作,但请注意,您也可以使用 SQLite/3 DNS-less。例如,使用pyodbcPython:

import pyodbc

connection_string = "Driver=MYGOOFYSQLITE3DRIVERTAG;Database=/path/to/database.db"
connection = pyodbc.connect(connection_string)
Run Code Online (Sandbox Code Playgroud)

请注意,对于Driver密钥,我引用了我在 中为驱动程序提供的标签odbcinst.ini。也许你想傻一点,也许你不想——关键是关键取决于你设置的内容,或者其他程序自动设置的内容,所以如果你需要知道驱动程序叫什么,看看它上odbcinst.ini.

有关连接字符串可以包含哪些内容的更多详细信息可以在sqliteodbc我们之前提到的驱动程序说明中找到。


归档时间:

查看次数:

5276 次

最近记录:

10 年,6 月 前