Solving Matplotlib Memory error which occurs while using pip install Matplotlib

Matplotlib Memory error which occurs while using pip install Matplotlib is an error which occurs when you have insufficient RAM to install matplotlib.

In today’s article I am going to deal with a confusing error and explain why it takes place and how to fix it, with a set of possible solutions.

Exploring the Matplotlib Memory error which occurs while using pip install Matplotlib

This is an error which occurs when you have insufficient RAM to install matplotlib.

Beware of mixing between errors. Double check if the error message looks like the error message bellow, then continue.

                                                                       #
File "/usr/local/lib/python2.7/dist-packages...", line ..., in dumps).encode("utf8"), MemoryError"
                                                                       #

Bellow is a number of tested methods that I have tried and that have worked for me.

The Method that Fixed my issue : Disable the cache by using –no-cache-dir when installing Matplotlib

When You have an insufficient memory space on your system , installing matplotlib will almost always fail.

This is caused by the caching mechanism used by pip. The cache is usually useless, especially for systems with limited memory, like : Docker images, Raspberry Pi, BeagleBone and sometimes ec2 instance etc.

To disable the cache we can use –no-cache-dir

So, instead of installing Matplotlib like this

                                                                       #
pip install matplotlib
                                                                       #

We should install Matplotlib using the command bellow.

                                                                       #
pip --no-cache-dir install matplotlib
                                                                       #

Now, we are trying to install Matplotlib without the cache that usually contains the installation files(.whl) and the source files (.tar.gz).

Now that we are using less space, the command above will likely succeed with no issues or errors.

This should be enough to get rid of the error for good. Thank you for reading the blog post to the end, cheers.

Summing-up : 

This is the end of our post, I hope this has been helpful and helped you solve the error or at least pointed you in the right direction.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/