# MemoryError (Unable to allocate X GiB for an array)

**Code:** `MemoryError` · **Category:** Python · **Seen on:** Python

Python couldn’t allocate memory — the data is larger than available RAM or address space.

## Meaning

NumPy/pandas raise “Unable to allocate X GiB for an array with shape …”. 32-bit Python is limited to ~2–4 GB regardless of RAM.

## Common causes

- Loading a huge file fully into memory
- Creating giant arrays/matrices
- 32-bit Python
- Memory leak in long loops

## Quick fix

1. Process in chunks (pd.read_csv(chunksize=...))
2. Use smaller dtypes (float32, category)
3. Install 64-bit Python
4. Use generators instead of lists

## Detailed fix by platform

### Python

1. `for chunk in pd.read_csv("big.csv", chunksize=100_000): process(chunk)`

## How to diagnose

1. **Size** — How large is the data vs RAM?
2. **Build** — 32- or 64-bit Python?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/python/memoryerror)
