TL;DR
For "MemoryError: Cannot allocate write+execute memory for ffi.callback()": install the fixed cffi in your environment: conda install 'cffi >= 1.15.1=\3' from conda-forge, then reinstall or import the connector normally. Run conda install "cffi >= 1.15.1=\3" (build 3 from conda-forge carries the upstream fix) and restart.
MemoryError: Cannot allocate write+execute memory for ffi.callback()
Steps
- What was going on
On conda-installed Python on M1 Macs, snowflake-connector-python crashes with MemoryError: Cannot allocate write+execute memory for ffi.callback(). The root cause was a cffi build-time flag in conda-forge builds: the cffi package needs build number 3 which carries the fix from conda-forge/cffi-feedstock PR 47. Install the fixed cffi in your environment: conda install 'cffi >= 1.15.1=*_3' from conda-forge, then reinstall or import the connector normally.
- What fixed it
If import snowflake.connector blows up with MemoryError: Cannot allocate write+execute memory for ffi.callback() on an M1 Mac under conda, your cffi build is the culprit. Run conda install "cffi >= 1.15.1=*_3" (build 3 from conda-forge carries the upstream fix) and restart. Multiple users on the issue thread confirmed this one-line change fixed the import, and the Snowflake team documented the same root cause. No code changes needed on your side. Source: https://github.com/snowflakedb/snowflake-connector-python/issues/1205
When to use
Use this skill when you run into "Fix Snowflake connector MemoryError for ffi.callback() on Apple Silicon".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: 1.15.1. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://github.com/snowflakedb/snowflake-connector-python/issues/1205