読者です 読者をやめる 読者になる 読者になる

EC2のt2.microインスタンスのubuntuにTensorFlowをインストールしようとしたがスペックが足りなかった

EC2の無料トライアルにインスタンスをつくったので V1.0がリリースされたTensorFlowを動かしてみようとしたけど無理でした

スペック

インスタンス:t2.micro
OS:Ubuntu Server 16.04
vCPU;1  (2.5 GHz, Intel Xeon Family)
メモリ:1GiB
ストレージ:8GiB

やったこと

TensorFlow公式に従ってpythonのvirturalenv環境を作成 (Python 2.7.12がインストールされました)

$ mkdir tensorflow
$ sudo apt-get install python-pip python-dev python-virtualenv 
$ virtualenv --system-site-packages tensorflow
$ source ~/tensorflow/bin/activate
(tensorflow)$

TensorFlowをインストール

(tensorflow)$ pip install --upgrade tensorflow
Collecting tensorflow
 Downloading tensorflow-1.0.0-cp27-cp27mu-manylinux1_x86_64.whl (44.1MB)
   99% |████████████████████████████████| 44.1MB 59.3MB/s eta 0:00:01Exception:
Traceback (most recent call last):
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/basecommand.py",
line 215, in main
   status = self.run(options, args)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/commands/install.py",
line 335, in run
   wb.build(autobuilding=True)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/wheel.py",
line 749, in build
   self.requirement_set.prepare_files(self.finder)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/req/req_set.py",
line 380, in prepare_files
   ignore_dependencies=self.ignore_dependencies))
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/req/req_set.py",
line 620, in _prepare_file
   session=self.session, hashes=hashes)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 821, in unpack_url
   hashes=hashes
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 659, in unpack_http_url
   hashes)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 882, in _download_http_url
   _download_url(resp, link, content_file, hashes)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 603, in _download_url
   hashes.check_against_chunks(downloaded_chunks)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/utils/hashes.py",
line 46, in check_against_chunks
   for chunk in chunks:
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 571, in written_chunks
   for chunk in chunks:
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/utils/ui.py",
line 139, in iter
   for x in it:
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/download.py",
line 560, in resp_read
   decode_content=False):
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py",
line 357, in stream
   data = self.read(amt=amt, decode_content=decode_content)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py",
line 314, in read
   data = self._fp.read(amt)
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py",
line 63, in read
   self._close()
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py",
line 50, in _close
   self.__callback(self.__buf.getvalue())
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.py",
line 275, in cache_response
   self.serializer.dumps(request, response, body=body),
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/serialize.py",
line 55, in dumps
   "body": _b64_encode_bytes(body),
 File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/_vendor/cachecontrol/serialize.py",
line 12, in _b64_encode_bytes
   return base64.b64encode(b).decode("ascii")
MemoryError

モリーエラーみたい

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl

でもダメ

メモリが足りないようなので500MBのスワップ領域を作成

$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288
$ sudo chown root:root /swapfile
$ sudo chmod 0600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

もう一度TensorFlowインストールしてみる

(tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl
:
Exception:
Traceback (most recent call last):
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/wheel.py", line 377, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
  File "/home/ubuntu/tensorflow/local/lib/python2.7/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib/python2.7/shutil.py", line 84, in copyfile
    copyfileobj(fsrc, fdst)
  File "/usr/lib/python2.7/shutil.py", line 52, in copyfileobj
    fdst.write(buf)
IOError: [Errno 28] No space left on device

ディスク容量が足りなくなった