我正在使用Python 2.7,如果我尝试安装Matplotlib,我会收到此错误,如果我使用" pip install matplotlib"
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 339, in run
requirement_set.prepare_files(finder)
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 355, in prepare_files
do_download, session=self.session,
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 782, in unpack_url
session,
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 667, in unpack_http_url
from_path, content_type = _download_http_url(link, session, temp_dir)
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 843, in _download_http_url
_download_url(resp, link, content_file)
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 615, in _download_url
for chunk in progress_indicator(resp_read(4096), 4096):
File "/usr/local/lib/python2.7/dist-packages/pip/utils/ui.py", line 46, in iter
for x in it:
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 580, in resp_read
decode_content=False):
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 256, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 186, in read
data = self._fp.read(amt)
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/filewrapper.py", line 54, in read
self.__callback(self.__buf.getvalue())
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/controller.py", line 205, in cache_response
self.serializer.dumps(request, response, body=body),
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/serialize.py", line 81, in dumps
).encode("utf8"),
MemoryError"
问题可能是什么? 我使用带有16gb SD卡的raspberry Pi 2。我仍然有8GB数据免费但仍然收到此错误。 请帮助
答案 0 :(得分:230)
这个错误即将到来,因为pip的缓存机制似乎是在缓存它之前尝试将整个文件读入内存...这在有限的内存环境中造成了问题,因为matplotlib是~50mb。
一个更简单的解决方案,直到pip被修补以使用常量空间缓存算法,就是使用pip
运行--no-cache-dir
以避免缓存:
$ pip --no-cache-dir install matplotlib
答案 1 :(得分:22)
似乎你没有足够的内存来从头开始构建matplotlib。为了克服这个问题,要么打开交换:
# create swap file of 512 MB
dd if=/dev/zero of=/swapfile bs=1024 count=524288
# modify permissions
chown root:root /swapfile
chmod 0600 /swapfile
# setup swap area
mkswap /swapfile
# turn swap on
swapon /swapfile
或者,如果你的SD卡上安装了raspbian,你可以从存储库安装matplotlib:
apt-get install python-matplotlib
答案 2 :(得分:1)
--no-cache-dir
对我不起作用。我刚刚关闭了所有应用程序,然后才能够完成安装。