LoginSignup
3
3

More than 5 years have passed since last update.

mojimojiのインストールに失敗した件。もしくはPython.hが無いと言われた場合に疑うべき問題

Posted at

この記事の概要

  • pythonの日本語処理ライブラリであるmojimojiをpipenvでインストールしようとしたら失敗した。
  • sudo apt-get install python3-devしてからやり直したら成功した。

症状

  • OSはUbuntu16.04
  • pythonは3.5
  • 環境はpipenvで管理している。

pipenvでmojimojiをインストールしようとした。

command
$ pipenv install mojimoji

こんなエラーになった。

error
(hoge-1jnfWo2E) sabaku20XX@R7:~/Documents/hoge$ pipenv install mojimoji
Installing mojimoji...
Collecting mojimoji
  Using cached https://files.pythonhosted.org/packages/6e/dd/b2fde54ecfd7f66e5a39ca0fd6245480af62e0d91dbe9d6a5d4551196e67/mojimoji-0.0.8.tar.gz
Building wheels for collected packages: mojimoji
  Running setup.py bdist_wheel for mojimoji: started
  Running setup.py bdist_wheel for mojimoji: finished with status 'error'
  Complete output from command /home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/bin/python3.5m -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-_eyqujx6/mojimoji/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-_msrwezq --python-tag cp35:
  running bdist_wheel
  running build
  running build_ext
  building 'mojimoji' extension
  creating build
  creating build/temp.linux-x86_64-3.5
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -I/home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/include/python3.5m -c mojimoji.cpp -o build/temp.linux-x86_64-3.5/mojimoji.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  mojimoji.cpp:4:20: fatal error: Python.h: No such file or directory
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Running setup.py clean for mojimoji
Failed to build mojimoji
Installing collected packages: mojimoji
  Running setup.py install for mojimoji: started
    Running setup.py install for mojimoji: finished with status 'error'
    Complete output from command /home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/bin/python3.5m -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-_eyqujx6/mojimoji/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-xtqn2oc_/install-record.txt --single-version-externally-managed --compile --install-headers /home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/include/site/python3.5/mojimoji:
    running install
    running build
    running build_ext
    building 'mojimoji' extension
    creating build
    creating build/temp.linux-x86_64-3.5
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -I/home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/include/python3.5m -c mojimoji.cpp -o build/temp.linux-x86_64-3.5/mojimoji.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    mojimoji.cpp:4:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------

Error:  An error occurred while installing mojimoji!
  Failed building wheel for mojimoji
Command "/home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/bin/python3.5m -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-_eyqujx6/mojimoji/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-xtqn2oc_/install-record.txt --single-version-externally-managed --compile --install-headers /home/sabaku20XX/.local/share/virtualenvs/hoge-1jnfWo2E/include/site/python3.5/mojimoji" failed with error code 1 in /tmp/pip-install-_eyqujx6/mojimoji/

いろいろ書いてあるがmojimoji.cpp:4:20: fatal error: Python.h: No such file or directoryの部分に注目した。mojimoji内部のcppファイルが必要なファイルを見つけられなかったようだ。

対処

ここでpython3-devに含まれるパッケージの情報を見てみる。

これをインストールすれば良いのかも知れない。

  • libpython3-dev (= 3.4.0-0ubuntu2)
    header files and a static library for Python (default)

インストール

$ sudo apt-get install python3-dev

今度はうまく行った。

$ pipenv install mojimoji
Installing mojimoji...
Collecting mojimoji
  Using cached https://files.pythonhosted.org/packages/6e/dd/b2fde54ecfd7f66e5a39ca0fd6245480af62e0d91dbe9d6a5d4551196e67/mojimoji-0.0.8.tar.gz
Building wheels for collected packages: mojimoji
  Running setup.py bdist_wheel for mojimoji: started
  Running setup.py bdist_wheel for mojimoji: finished with status 'done'
  Stored in directory: /home/sabaku20XX/.cache/pipenv/wheels/dc/b6/da/975efa6e69b47502dacc80f5de51f73f07ee8a2d030c76a569
Successfully built mojimoji
Installing collected packages: mojimoji
Successfully installed mojimoji-0.0.8

Adding mojimoji to Pipfiles [packages]...
Pipfile.lock (506467) out of date, updating to (f78446)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (f78446)!
Installing dependencies from Pipfile.lock (f78446)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 43/43 — 00:00:02

補足

  • mojimojiPython.hが無いというエラーメッセージを出していた。
  • python3-devに含まれるlibpython3-devheader files and a static library for Pythonと書いてある。
  • だからpython3-devをインストールすれば直るだろう。

このように推測してpython3-devをインストールしたが、本当にlibpython3-devPython.hが含まれているのか確認してみよう。

前にちょっと書いたが、/var/cache/apt/archivesにaptでインストールしたパッケージの.debファイルが残っている。

/var/cache/apt/archives$ sudo find . | grep libpython
./libpython3-dev_3.5.1-3_amd64.deb
./libpython3.5-dev_3.5.2-2ubuntu0~16.04.4_amd64.deb
  • dpkg --contentsコマンドでパッケージに含まれるファイルの一覧が出てくる。
  • grepでPython.hを探す。
/var/cache/apt/archives$ dpkg --contents libpython3.5-dev_3.5.2-2ubuntu0~16.04.4_amd64.deb  | grep Python.h
-rw-r--r-- root/root      2906 2017-11-29 01:51 ./usr/include/python3.5m/Python.h

あった。

Python.hが無いと言われた時は、python3-devが無い可能性が高いという事がわかった。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3