Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with an Access database in Python on non-Windows platform (Linux or Mac)

Tags:

I want to access the data in a Microsoft Access database. I have some .accdb and .mdb files and want to read them in Python.

From my research, pyodbc can only be used on Windows platform, but I am working on Mac OS X. I am new to Python.

The other option is if I could export the data from the database to a csv and then use in python.

Any help or starting would be highly appreciated.

like image 583
user2948166 Avatar asked Aug 31 '14 22:08

user2948166


People also ask

Can you run Access database on a Mac?

You can run your Access database from anywhere in the world where there is an Internet Connection. Users running Access on a Mac will get the same experience as users running it on their PC. There are no code changes required as Access is, in reality, running on a Windows machine.

Can you use Python with Access database?

To connect Python to Access: Add the path where you stored the Access file (after the syntax DBQ=). Don't forget to add the MS Access file extension at the end of the path ('accdb') Add the table name within the select statement.

Can I use MS Access on Linux?

Microsoft Office Access is not available for Linux but there are plenty of alternatives that runs on Linux with similar functionality. The best Linux alternative is LibreOffice - Base, which is both free and Open Source.

Is Python compatible with Microsoft Access?

Python can connect to and work with a wide variety of database applications, MS Access database is one of them. We'll walk through how to use the pyodbc library to interact with an Access database.


1 Answers

On Mac OSx and Ubuntu 18.04 you can use pandas_access

From the documentation:

import pandas_access as mdb  db_filename = 'my_db.mdb'  # Listing the tables. for tbl in mdb.list_tables(db_filename):   print(tbl)  # Read a small table. df = mdb.read_table(db_filename, "MyTable") 

On Ubuntu you may need to run:

sudo apt install mdbtools 
like image 64
Vipassana Vijayarangan Avatar answered Sep 19 '22 14:09

Vipassana Vijayarangan