我试图从一个非常简单的Access文件中获取数据到python代码中。我按照这个视频中的说明:https://www.youtube.com/watch?v=zw9P2wSnoIo
我的代码如下:import pypyodbc
con=pypyodbc.connect('DRIVER={Microsoft Access Driver(*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;{FIL=MS Access};DriverId=25;{DefaultDir=C:/Users/climate1/Documents/Test};DBQ=C:/Users/climate1/Documents/Test/dogs1.mdb;')
cursor=con.cursor()
cursor.execute("SELECT * FROM doggos")
for row in cursor,fetchall():
print(row)
但它似乎找不到正确的驱动程序,我收到了这个错误:File "doggos.py", line 5, in
con=pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;{FIL=MS Access};DriverId=25;{DefaultDir=C:/Users/climate1/Documents/Test};DBQ=C:/Users/climate1/Documents/Test/dogs1.mdb;')
File "C:\Users\climate1\Documents\SaraCode\lib\site-packages\pypyodbc.py", line 2454, in init
self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
File "C:\Users\climate1\Documents\SaraCode\lib\site-packages\pypyodbc.py", line 2507, in connect
check_success(self, ret)
File "C:\Users\climate1\Documents\SaraCode\lib\site-packages\pypyodbc.py", line 1009, in check_success
ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
File "C:\Users\climate1\Documents\SaraCode\lib\site-packages\pypyodbc.py", line 985, in ctrl_err
raise Error(state,err_text)
pypyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified')
我对python并不陌生,但我对windows和Access都相当陌生。我使用的是python3.6.3版本,并使用pip安装下载了pypyodbc。在
我尝试过在32位到64位之间返回第四位,还使用了一些基本语法(正斜杠和反斜杠等等)