Python3.9 malloc error: can’t allocate region
( 26 Articles)
When running Python code that imports some modules (request, numpy, pandas, etc), I fall into the following error:
Python malloc: can't allocate region Set a breakpoint in malloc_error_break to debug
This happens with both global and virtual environment.
More error messages:
RuntimeError: Polyfit sanity test emitted a warning, most likely due to using a buggy Accelerate backend. If you compiled yourself, see site.cfg.example for information. Otherwise report this to the vendor that provided NumPy. RankWarning: Polyfit may be poorly conditioned
macOS Big Sur 11.0.1 Homebrew 2.5.11 python 3.9 (installed by using Homebrew)
If you run into the mentioned issue like me, don’t be panic. We’ll fix it within a few minutes.
The culprit that causes the problem might not be you or your Mac but there is something wrong with [email protected] from Homebrew. Everything you need to do is to remove the brew version of Python and install Python for macOS provided by python.org:
1. Removing Python installed using Homebrew by executing this command:
brew uninstall --ignore-dependencies [email protected]
2. Download and install one of the latest versions of Python from https://www.python.org/downloads/mac-osx/.
Done. Hope this helps!