MemoryError (Unable to allocate X GiB for an array)
Python couldn’t allocate memory — the data is larger than available RAM or address space.
Seen on:
Python
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
- Process in chunks (pd.read_csv(chunksize=...))
- Use smaller dtypes (float32, category)
- Install 64-bit Python
- Use generators instead of lists
Detailed fix by platform
Python
for chunk in pd.read_csv("big.csv", chunksize=100_000): process(chunk)
How to diagnose
- Size — How large is the data vs RAM?
- Build — 32- or 64-bit Python?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026