I am using Python 2.7, If i try to install Matplotlib I am getting this error if i use "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"
What might the problem be?
I am using raspberry Pi 2 with a 16gb SD card. I still have 8gb data free but still getting this error.
Kindly help
This error is coming up because, it seems, pip's caching mechanism is trying to read the entire file into memory before caching it… which poses a problem in a limited-memory environment, as matplotlib is ~50mb.
A simpler solution, until pip is patched to use a constant-space caching algorithm, is to run pip with --no-cache-dir to avoid the cache:
$ pip --no-cache-dir install matplotlib
It seems that you have insufficient RAM to build matplotlib from scratch. To overcome that, either turn on swap:
# 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
Or, if you have raspbian installed on your SD card, you can install matplotlib from the repository:
apt-get install python-matplotlib
--no-cache-dir didn't work for me. I just closed all apps and only then I was able to finish installation.
Related
I tried pip3 install torch --no-cache-dir and, after few seconds, I got this:
Collecting torch
Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)
100% |████████████████████████████████| 753.4MB 5.7MB/s
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run
requirement_set.prepare_files(finder)
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "/usr/lib/python3/dist-packages/pip/download.py", line 821, in unpack_url
hashes=hashes
File "/usr/lib/python3/dist-packages/pip/download.py", line 663, in unpack_http_url
unpack_file(from_path, location, content_type, link)
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 617, in unpack_file
flatten=not filename.endswith('.whl')
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 506, in unzip_file
data = zip.read(name)
File "/usr/lib/python3.6/zipfile.py", line 1338, in read
return fp.read()
File "/usr/lib/python3.6/zipfile.py", line 858, in read
buf += self._read1(self.MAX_N)
File "/usr/lib/python3.6/zipfile.py", line 948, in _read1
data = self._decompressor.decompress(data, n)
MemoryError
What should I do now to install PyTorch?
I tried almost every method mentioned on google. I am working on Ubuntu, I tried using conda too, but I am unable to use that package outside conda.
For pip environment use this
pip3 install torchvision
For conda environment use this (run this command on anaconda prompt)
conda install PyTorch -c PyTorch
Update
Use this code to turn off your cache
pip3 --no-cache-dir install torchvision
or
pip3 install torchvision--no-cache-dir
or
pip install --no-cache-dir torchvision
Try one by one
Traceback (most recent call last):<br>
File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main<br>
status = self.run(options, args)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 335, in run<br>
wb.build(autobuilding=True)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build<br>
self.requirement_set.prepare_files(self.finder)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))<br>
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 821, in unpack_url
hashes=hashes<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 659, in unpack_http_url
hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 882, in _download_http_url
_download_url(resp, link, content_file, hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 603, in _download_url
hashes.check_against_chunks(downloaded_chunks)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/utils/hashes.py", line 46, in check_against_chunks<br>
for chunk in chunks:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 571, in written_chunks
for chunk in chunks:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/utils/ui.py", line 139, in iter<br>
for x in it:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 560, in resp_read
decode_content=False):<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 357, in stream<br>
data = self.read(amt=amt, decode_content=decode_content)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 324, in read<br>
flush_decoder = True<br>
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 246, in _error_catcher<br>
raise ReadTimeoutError(self._pool, None, 'Read timed out.')<br>
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
I solved it by modifying the command like this:
pip --default-timeout=100 install THEPACKAGENAME
You can also try installing using wheel packages.
The Wheel packages depend on the kind of operating system you have, the python version and whether you want to install with CPU/GPU support.
Also upgrade you protobuf before installing Tensorflow.
Please find a list of packages here:
https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package
You can then issue this command :
$ sudo pip install --upgrade <TF wheel package URL> - For Python 2.7
$ sudo pip3 install --upgrade <TF wheel package URL> - For Python 3.x
Tensorflow site has some details on some common installation problems. You can look at those as well, just in case.
https://www.tensorflow.org/install/install_linux#common_installation_problems
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:
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
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
I'm trying to install PIP to run an older application and have followed a number of steps the final hurdle is installing PIP. The reason for this is the functionality I'm trying to use is showing this error:
ImportError: No module named PIL
I followed the instruction at http://prateekvjoshi.com/2014/04/19/how-to-install-pil-on-ubuntu/
And had to change the command slightly to:
sudo pip install PIL --allow-external PIL --allow-unverified PIL
I'm getting some errors and not sure how to resolve these:
Can anyone share any ideas? I'm sure its just a library or something missing?
Thanks
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1197, in prepare_files
do_download,
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1375, in unpack_url
self.session,
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 582, in unpack_http_url
unpack_file(temp_location, location, content_type, link)
File "/usr/lib/python2.7/dist-packages/pip/util.py", line 625, in unpack_file
untar_file(filename, location)
File "/usr/lib/python2.7/dist-packages/pip/util.py", line 543, in untar_file
tar = tarfile.open(filename, mode)
File "/usr/lib/python2.7/tarfile.py", line 1678, in open
return func(name, filemode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1727, in gzopen
**kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
return cls(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1574, in __init__
self.firstmember = self.next()
File "/usr/lib/python2.7/tarfile.py", line 2335, in next
raise ReadError(str(e))
ReadError: invalid header
Storing debug log for failure in /home/peek/.pip/pip.log
Maybe you can check again, how many bits of your computer?
install PIL on 64-bit Ubuntu 12.04
How about this?
https://askubuntu.com/questions/507459/pil-install-in-ubuntu-14-04-1-lts
$ sudo apt-get build-dep python-imaging
$ sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
$ sudo pip install Pillow
For Check Version on Python
>>> import PIL
>>> PIL.VERSION
'1.1.7'
On a MBP, following instructions (http://techblog.rosedu.org/python-environment.html), I installed Xcode 4.4.1, brew (brew doctor says all set), and then python. Next, I tried to setup virtualenv:
> $MYPYTHON/bin/python distribute_setup.py
> $MYPYTHON/bin/easy_install pip
> $MYPYTHON/bin/pip install virtualenv
I then created a virtual environment and tried to install django:
> $MYPYTHON/bin/virtualenv $MYENV
> $MYENV/bin/pip install Django
It downloads 98% and then hangs for a while, and finally I get a traceback indicating a timeout:
pcm#pcm-mac[302]% $MYENV/bin/pip install django
Downloading/unpacking django
Downloading Django-1.4.1.tar.gz (7.7Mb): 7.5Mb downloaded
Exception:
Traceback (most recent call last):
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 985, in prepare_files
self.unpack_url(url, location, self.is_download)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1109, in unpack_url
retval = unpack_http_url(link, location, self.download_cache, self.download_dir)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 451, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 368, in _download_url
chunk = resp.read(4096)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 553, in read
s = self.fp.read(amt)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
timeout: timed out
I see the same thing, if I just run the version of pip from /usr/local/bin/. I tried other packages (selenium, mock) and they downloaded and installed fine.
I'm at a loss as to what I may be doing wrong, or if there is some issue with django installs via pip. Advice?
Use:
pip --default-timeout=60 install django