pip安装Matplot库时遇到MemoryError的错误,类似以下的提示信息。
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” File “/usr/local/lib/python2.7/dist-packages/pip/_vendor/cachecontrol/serialize.py”,
line 81, in dumps
).encode(“utf8”), MemoryError”
查找到是由于pip的缓存机制尝试将希望安装库的整个文件缓存到内存,而在限制缓存大小的环境中如果安装包较大就会出现MemoryError的这个错误。
解决方法:
$ pip --help
......省略......
--client-cert Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir Store the cache data in .
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
可以看到pip有个–no-cache-dir参数,失能缓冲即可。
$pip --no-cache-dir install matplotlib