我正在尝试在需要 matplotlib 的ec2实例上运行脚本,显然默认情况下不会安装它。所以我正在努力做到这一点
pip install -U matplotlib
以下是文字版本:
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
答案 0 :(得分:1)
如果您位于EC2实例的较低层,则分配给该实例的内存可能不足以用于编译mathplot。
如果您使用的是较低层的ec2实例,则可以考虑启用swap。以下信息来自digitalocean网站。 https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
我们可以通过输入以下内容来查看系统是否有任何已配置的交换:
sudo swapon -s
检查当前的交换使用情况:
free -m
如果显示Swap:0 0 0,则表示没有Swap 缓存的总使用的免费共享缓冲区 纪录:3953 154 3799 0 8 83 - / + buffers / cache:62 3890 交换:0 0 0
检查空间大小
df -h
确保您有足够的空间并创建:
sudo fallocate -l 2G /swapfile
验证空间信息:
ls -lh /swapfile
返回上述命令的结果:
-rw-r--r-- 1 root root **2.0G** Apr 28 17:19 /swapfile
启用交换文件
sudo chmod 600 /swapfile
键入以下命令验证文件是否具有正确的权限:
ls -lh /swapfile
设置交换空间:
sudo mkswap /swapfile
使用交换空间:
sudo swapon /swapfile
检查程序是否正确:
sudo swapon -s
检查可用空间:
free -m
交换应该在总字段中指示超过0。
使交换文件永久化:
sudo nano /etc/fstab
在文件键的末尾:
/swapfile none swap sw 0 0
完成上述步骤后,您可以考虑使用yum install来安装python-matplotlib:
sudo yum install python-matplotlib