I want to link my Python packages to my Access database, but I get this error. I use python 2.7.12 (shell).
import pypyodbc
#create connection
con = pypyodbc.connect('DRIVER={Microsoft Access-Treiber (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=//Users/123GuteLaune/DatabaseMAformat.mdb')
cursor = con.cursor()
#Select Data
cursor.execute("SELECT * from TW-DS")
for row in cursor.fetchone():
print(row)}
Traceback (most recent call last):
File "", line 1, in
import pypyodbc
ImportError: No module named pypyodbc
Edit
Hi after second installation following error occurs
Traceback (most recent call last): File "/Users/123GuteLaune/Python/connectionprogramm.py", line 4, in con = pypyodbc.connect('DRIVER={Microsoft Access-Treiber (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=//Users/123GuteLaune/DatabaseMAformat.mdb') File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 2435, in init self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 2484, in connect check_success(self, ret) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 989, in check_success ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 976, in ctrl_err err_list.append((from_buffer_u(state), from_buffer_u(Message), NativeError.value)) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 483, in UCS_dec uchar = buffer.raw[i:i + ucs_length].decode(odbc_decoding) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_32.py", line 11, in decode return codecs.utf_32_decode(input, errors, True) UnicodeDecodeError: 'utf32' codec can't decode bytes in position 0-1: truncated data
Edit on 12.10.2016
I use a Mac with macOS El Captain. I have the program "Parallels" on my laptop for using Access in a virtual machine. Python is installed on the Mac side.
What must I change that Python can use the ODBC interface to Access?
Edit 13.10.2016
I find a the toolkit "pyodbc" i think this should work on mac but again i can not ran the setup file i got the error. I already installed homebrew and find this dokumentation for installing (https://github.com/lionheart/django-pyodbc/wiki/Mac-setup-to-connect-to-a-MS-SQL-Server)
Error in python: Traceback (most recent call last): File "/Users/123GuteLaune/connectionprogramm.py", line 1, in import pyodbc ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc.so, 2): Library not loaded: /usr/local/lib/libodbc.2.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc.so Reason: image not found
If you are running Python on the Mac side then you need to use a driver that is compatible with macOS. The Microsoft Access-Trebier (*.mdb)
ODBC driver is a Windows DLL (ODBCJT32.DLL) and I doubt very much that the Mac version of Python can use it.
You may be interested in the related question here:
Read an Access database in Python on non-Windows platform (Linux or Mac)