Getting ModuleNotFoundError when importing airtable module in Python

I’m having trouble with a Python script that connects to Airtable’s API. When I try to run my code, I keep getting an error saying the airtable module cannot be found.

I set up a virtual environment and created a file called fetch_records.py with this code:

import requests
from airtable import airtable

api_client = airtable.Airtable('appB4x9YYp3KzmqTw', 'YOUR_API_TOKEN')
api_client.get('Projects')

When I execute the script, I get this error message:

(myenv) PS C:\Dev\python_scripts\myenv> python fetch_records.py
Traceback (most recent call last):
  File "fetch_records.py", line 2, in <module>
    from airtable import airtable
ModuleNotFoundError: No module named 'airtable'

What am I missing here? I’m pretty new to working with APIs in Python so I might have skipped something basic. Any help would be great!

You’re getting that error because the airtable package isn’t installed in your virtual environment. Install it with pip first. However, it seems you’re trying to use the older airtable-python-wrapper library. In that case, execute pip install airtable-python-wrapper while ensuring your virtual environment is active. Your import statement should work after that. Additionally, verify that you’re using the correct format for your API token, as newer Airtable versions require personal access tokens rather than API keys.

hey emma! i think you just need to install the airtable package. try running pip install pyairtable inside your virtual env, that should solve the ModuleNotFound error. good luck!