Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

ChromebookにCrostiniでpipとmatplotlibとJupyterをインストール

More than 1 year has passed since last update.

はじめに

ChromebookでPythonつかってグラフ描いてみたいなと思って色々やってみた。

pip

pipがなかったので入れた。

$ which pip
$ curl -O https://bootstrap.pypa.io/get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1622k  100 1622k    0     0  2592k      0 --:--:-- --:--:-- --:--:-- 2592k
$ sudo python get-pip.py 
Successfully installed pip-18.1 setuptools-40.6.3 wheel-0.32.3

ここを参考にした。
Setting up a fresh crostini in Chrome OS · GitHub

matplotlib

なかなか素直には入らない

$ pip install matplotlib

  _posixsubprocess.c:16:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                      ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for subprocess32
  Running setup.py clean for subprocess32
Failed to build subprocess32
Installing collected packages: numpy, six, cycler, kiwisolver, python-dateutil, pytz, subprocess32, backports.functools-lru-cache, pyparsing, matplotlib
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/numpy-1.15.4.dist-info'
Consider using the `--user` option or check the permissions.
$ sudo pip install matplotlib

  _posixsubprocess.c:16:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                      ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for subprocess32
  Running setup.py clean for subprocess32
Failed to build subprocess32
Installing collected packages: numpy, six, cycler, kiwisolver, python-dateutil, pytz, subprocess32, backports.functools-lru-cache, pyparsing, matplotlib
  Running setup.py install for subprocess32 ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-tssmeB/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-uigJgF/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying subprocess32.py -> build/lib.linux-x86_64-2.7
    running build_ext
    running build_configure
     _posixsubprocess_config.h is already up to date.
    building '_posixsubprocess32' extension
    creating build/temp.linux-x86_64-2.7
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
    _posixsubprocess.c:16:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-tssmeB/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-uigJgF/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-tssmeB/subprocess32/

調べたら、python-dev入れろってサイト出て来るので、入れてみた。

$ sudo apt-get install python-dev

このあと、sudo pip install matplotlibしたらいけた。
ためしてみた。

$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
    from . import tkagg  # Paint image to Tk photo blitter extension.
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/tkagg.py", line 5, in <module>
    from six.moves import tkinter as Tk
  File "/usr/local/lib/python2.7/dist-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/usr/local/lib/python2.7/dist-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/local/lib/python2.7/dist-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package

python-tkいるっぽい。そもそも、デスクトップ環境じゃないから、グラフ表示はいろいろめんどくさいのか。IDEを入れるといいのかも。

Matplotlib showing plots? : Crostini

What's the best Python IDE for crostini (hoping to avoid harsh crashing issues) : Crostini

Jupyter

それなら、Jupyter入れるかという気になってきた。

Jupyter Notebook : Crostini

Running a notebook server — Jupyter Notebook 5.7.3 documentation

$ sudo pip install jupyter

普通に入った。
すばらしい。

image.png

おわりに

いい感じに環境構築できた。
ラズパイとかGCP使ってやってもいいんやけども。
Chromebookすばらしい。
Python3でもいけんのかな?
気が向いたら、やってみよう。

optimisuke
Feedback Welcome
acall
ACALLは、「Life in Work and Work in Life for Happiness」をVISIONとして、どこでも安心・安全・快適なワークスタイルを実現するスマートオフィスプラットフォーム「WorkstyleOS」を開発・提供しています。オフィスワークとリモートワークのベストミックスを通じて、人々の「くらし」と「はたらく」を自由にデザインできる世界を目指します。
https://www.workstyleos.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away