0

I am trying to run a script on an ec2 instance which requires matplotlib and apparently it is not installed by default. So I am trying to do it

pip install -U matplotlib

as you can see in the image, I get this error: enter image description here

and here is the text version:

Collecting matplotlib   Downloading matplotlib-2.0.0.tar.gz (53.2MB)
    99% |████████████████████████████████| 53.2MB 24.0MB/s eta 0:00:01  Exception:   Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 246, in main
      status = self.run(options, args)
    File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
      requirement_set.prepare_files(finder)
    File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 345, in prepare_files
      functools.partial(self._prepare_file, finder))
    File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 290, in _walk_req_to_install
      more_reqs = handler(req_to_install)
    File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 487, in _prepare_file
      download_dir, do_download, session=self.session,
    File "/usr/lib/python2.7/dist-packages/pip/download.py", line 827, in unpack_url
      session,
    File "/usr/lib/python2.7/dist-packages/pip/download.py", line 673, in unpack_http_url
      from_path, content_type = _download_http_url(link, session, temp_dir)
    File "/usr/lib/python2.7/dist-packages/pip/download.py", line 888, in _download_http_url
      _download_url(resp, link, content_file)
    File "/usr/lib/python2.7/dist-packages/pip/download.py", line 621, in _download_url
      for chunk in progress_indicator(resp_read(4096), 4096):
    File "/usr/lib/python2.7/dist-packages/pip/utils/ui.py", line 133, in iter
      for x in it:
    File "/usr/lib/python2.7/dist-packages/pip/download.py", line 586, in resp_read
      decode_content=False):
    File "/usr/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 273, in stream
      data = self.read(amt=amt, decode_content=decode_content)
    File "/usr/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 203, in read
      data = self._fp.read(amt)
    File "/usr/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/filewrapper.py", line 54, in read
      self.__callback(self.__buf.getvalue())
    File "/usr/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/controller.py", line 224, in cache_response
      self.serializer.dumps(request, response, body=body),
    File "/usr/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/serialize.py", line 81, in dumps
      ).encode("utf8"),   MemoryError
1

1 Answer 1

2

If you are on a lower tier of the EC2 instance, the memory allocated to the instance might not be sufficient to used to compile the mathplot.

If you are on a lower tier ec2 instance, you may consider to switch on swap. The following information was summarized from digitalocean website. https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

We can see if the system has any configured swap by typing:

sudo swapon -s

Check current swap usage:

free -m

If it shows Swap: 0 0 0 that means there is no Swap total used free shared buffers cached Mem: 3953 154 3799 0 8 83 -/+ buffers/cache: 62 3890 Swap: 0 0 0

Check space size

df -h

Make sure you have sufficient space and create:

sudo fallocate -l 2G /swapfile

Verify space information:

ls -lh /swapfile

Return result of above command:

-rw-r--r-- 1 root root **2.0G** Apr 28 17:19 /swapfile

Enabling the Swap File

sudo chmod 600 /swapfile

Verify that the file has the correct permissions by typing:

ls -lh /swapfile

Setup swap space:

sudo mkswap /swapfile

Use the swap space:

sudo swapon /swapfile

Check the procedure is correct:

sudo swapon -s

Check free space:

free -m

The Swap should have indicated more than 0 in total field.

Make the Swap File Permanent:

sudo nano /etc/fstab

At the end of the file key in :

/swapfile   none    swap    sw    0   0

After complete the above steps, you may consider to use yum install to install python-matplotlib:

sudo yum install python-matplotlib 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.