PYODBC找不到MSSQL驱动程序

时间:2019-08-31 16:30:43

标签: python-3.x pyodbc unixodbc

我正在尝试使用如下所示的简单python脚本连接到SQL Server。

import Quartz

class ViewController: NSViewController, QLPreviewPanelDataSource, QLPreviewPanelDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let windowNextResponder = self.view.window?.nextResponder
        self.view.window?.nextResponder = self
        self.nextResponder = windowNextResponder
    }

    // *** Quicklook stuff ***

    @IBAction func quickLookButtonAction(_ sender: Any) {
        guard qlPanel != nil else {
            return
        }

        if qlPanel!.currentController == nil {
            print ("No controller")
            //qlPanel!.windowController = self.view.window?.windowController
            // qlPanel!.updateController()
        } else {
            print (qlPanel!.currentController)
        }
        qlPanel!.delegate = self
        qlPanel!.dataSource = self

        qlPanel!.makeKeyAndOrderFront(self)
    }

    func numberOfPreviewItems(in panel: QLPreviewPanel!) -> Int {
        return CSVarrayController.selectedObjects.count
    }

    func previewPanel(_ panel: QLPreviewPanel!, previewItemAt index: Int) -> QLPreviewItem! {
        let file = CSVarrayController.selectedObjects[index] as! CSVfile
        return file.url as NSURL
    }
    override func acceptsPreviewPanelControl(_ panel: QLPreviewPanel!) -> Bool {
        return true
    }
    override func beginPreviewPanelControl(_ panel: QLPreviewPanel!) {
        panel.dataSource = self
        panel.delegate = self
    }

    override func endPreviewPanelControl(_ panel: QLPreviewPanel!) {
        panel.dataSource = nil
        panel.delegate = nil
    }
} 

唯一的区别是我出于明显的原因删除了config值。但是,当我运行此脚本时,出现以下错误:

import pyodbc

details = {
    'server': '<hostname>',
    'database': '<database>',
    'username': '<username>',
    'password': '<password>'
}

connect_string = 'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};PORT=1443;DATABASE={database};UID={username};PWD={password}'.format(**details)

connection = pyodbc.connect(connect_string)
print(connection)

作为参考,运行Traceback (most recent call last): File "connect.py", line 12, in <module> connection = pyodbc.connect(connect_string) pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)") 的输出给我:

odbcinst -j

unixODBC 2.3.4 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /home/bipvanwinkle/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8

cat /etc/odbcinst.ini

[SQLServer] Description = ODBC Driver 17 for SQL Server Driver = /usr/lib/x86_64-linux-gnu/libodbc.so Setup = /usr/lib/x86_64-linux-gnu/libodbc.so.1 UsageCount = 1 FileUsage = 1

cat /etc/odbc.ini

[SQLServer] Description = ODBC Driver 17 for SQL Server Driver = /usr/lib/x86_64-linux-gnu/libodbc.so Servername = Database = UID = Port = 1433 : /usr/lib/x86_64-linux-gnu/libodbc.so

ls /usr/lib/x86_64-linux-gnu/libodbc.so

ldd /usr/lib/x86_64llinux-gnu/libodbc.so

如果有帮助,则/etc/odbcinst.ini和/etc/odbc.ini最初都是空的。我使用在网上找到的模板来填写它们。我肯定会犯错误。

有什么想法我做错了吗?

P.S。我正在Ubuntu 17.10上运行它

0 个答案:

没有答案