LoginSignup
2

More than 3 years have passed since last update.

posted at

updated at

anacondaにsentencepieceをwheelファイル経由でインストールする

背景

  • 機械学習関連のライブラリをインストールするためにanacondaを使用
  • コンフリクトを避けるためpipは使わずcondaでパッケージ管理
  • sentencepieceのPythonバインディングをインストールしたい

実行環境

  • CentOS 6.7
  • (pyenv)anaconda3-5.3.1
  • conda createで仮想環境を作ってその中でインストール

リポジトリにあるか確認

$ conda search sentencepiece

ヒットせず。

conda skeleteonを使ってみる(失敗)

  • anacondaのリポジトリになくてPyPIにある(pip installできる)パッケージは、conda skeletonを使うことでcondaにインストールするためのレシピファイルを作成できる
$ conda skeleton pypi sentencepiece

Error: No source urls found for sentencepiece
というエラーが出て失敗。

sentencepieceのPyPIにはwhlファイルはあるが
tar.gzファイルがなかったのでインストールできず失敗した模様。

自分でcondaレシピを作る

  • conda skeletonで作られるレシピを参考に作る
  • meta.yaml, build.shが必要って書いてあったけどmeta.yamlだけでインストールできた
  • sentencepiece/meta.yaml を編集する
$ mkdir sentencepiece
$ vim sentencepiece/meta.yaml
  • meta.yaml はこんな感じ

{% set name = "sentencepiece" %}
{% set version = "0.1.82" %}

package:
  name: "{{ name|lower }}"
  version: "{{ version }}"

source:
  url: https://github.com/google/sentencepiece/releases/download/v0.1.82/sentencepiece-0.1.82-cp37-cp37m-manylinux1_x86_64.whl
  sha256: 3fc02ba62f2d5c624f3f107cc256c1c5f877fb7fa80754e2e7cd7f0aa5e0c86f

build:
  number: 0
  script: "{{ PYTHON }} -m pip install sentencepiece-0.1.82-cp37-cp37m-manylinux1_x86_64.whl --no-deps --ignore-installed -vvv "
requirements:
  host:
    - pip
    - python
  run:
    - python
test:
  imports:
    - sentencepiece
  • ポイント
    • 先頭にインストール対象のライブラリ名(sentencepiece)とバージョン(0.1.82)を記述する
    • source.urlにGitHub上のwhlファイルのURLを記述する
    • sha256チェックサムはなくても動くらしいが、一応事前にダウンロードしてチェックサムを調べてから書いておく
    • build.scriptにwhlファイルをpip installするコマンドを書く(build.shの代わり)
    • --no-deps --ignore-installedを付けているのは他の依存ライブラリをインストールさせないため
    • もしかしたら必要ない行があるかも
  • できたらビルドする
$ conda build sentencepiece
最後にファイルが残ってると言われるので掃除する
$ conda build purge
  • ビルドが無事完了したらインストールする
$ conda install --use-local sentencepiece
  • インストールが完了したら作成したレシピディレクトリを削除する
$ rm -r sentencepiece

まとめ

  • conda skeleton pypiで上手くレシピが作れなくても自分でmeta.yaml書けばインストールできる
  • wheelファイルがあるライブラリなら大体condaでもインストールできそう

参考

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
What you can do with signing up
2