LoginSignup
11
7

More than 3 years have passed since last update.

冴えない彼氏のKH-coderの使い方(Mac導入編)

Last updated at Posted at 2020-10-26

はじめに

 KH-coderをMacで使おうと思いたち、インストールしようとしたのである。その際、参考となるサイトが少ないことに辟易し、ここにその方法を記そうと思い立った次第である。
(決してcpanmをclean upしようとして、sudo rm -rfして 3ヶ月間のデータを失ったからでない←聞かれてない)
今回は導入編であるので、具体的な解析については他のサイトを読んでほしい。

後、タイトルに関しては察してくれ。

実行環境

MacBook Pro(15-inch,2018)
プロセッサ 2.9 Ghz Intel Core i9
メモリ 32GB 2400 MHz DDR4
OS:macOS Mojave(ver.10.14.6)

前準備

X-code,Homebrewをインストールできていない場合

X-codeのインストール

xcode-select --install

Homebrewをインストール

Homebrewの公式サイト(https://brew.sh/index_ja.html) にインストールコマンドが掲載されているので、それに載っているスクリプトをターミナルを開き実行。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

インストール後の確認

brew doctor #インストール完了後の確認
brew --version

HomebrewでGitをインストール

brew install git

準備

XQuartzをインストール

このサイト(https://www.xquartz.org/index.html )のdmgをインストール

Stanford-Posttaggerをインストール

Stanford Log-linear Part-Of-Speech Tagger(https://nlp.stanford.edu/software/tagger.shtml#About)の公式サイトからインストールする。

openjdkのインストール

brew install openjdk13

mecabのインストール

brew install mecab
brew install mecab-ipandic

mysqlのインストール

brew install mysql

インストール終了後

brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
#成功すると上記のように表示される

起動後、次のコマンドを実行しパスワードを設定する。
コマンドを実行すると、最初にVALIDATE PASSWORD PLUGINという強固なパスワード設定を助けるプラグインを使用するかどうかを質問される。
(今回私はローカルでの使用しか想定していため、何も入力しなかった。)

次にrootユーザーのパスワードを設定する

mysql_secure_installation

(今回はパスワードを設定せず、次に進んだ)

mysql -u root

これで

(base) user:~ user$ mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.22 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

となれば成功。

mysqlの起動,終了

起動

brew services start mysql

もしくは

mysql.server start

####終了
```bash
brew services stop mysql

もしくは

mysql.server stop

Rのインストール

brew cask  install R

R単体と同時にRstudio(https://rstudio.com/products/rstudio/ )も一緒にインストールした

以下KH-coderを動かすために必要なパッケージ

install.packages("ade4", dependencies=TRUE)
install.packages("amap", dependencies=TRUE)
install.packages("Cairo", dependencies=TRUE)
install.packages("cluster", dependencies=TRUE)
install.packages("codetools", dependencies=TRUE)
install.packages("colorspace", dependencies=TRUE)
install.packages("dichromat", dependencies=TRUE)
install.packages("foreign", dependencies=TRUE)
install.packages("ggdendro", dependencies=TRUE)
install.packages("ggplot2", dependencies=TRUE)
install.packages("ggnetwork", dependencies=TRUE)
install.packages("ggsci", dependencies=TRUE)
install.packages("gtable", dependencies=TRUE)
install.packages("igraph", dependencies=TRUE)
install.packages("KernSmooth", dependencies=TRUE)
install.packages("lattice", dependencies=TRUE)
install.packages("maptools", dependencies=TRUE)
install.packages("MASS", dependencies=TRUE)
install.packages("Matrix", dependencies=TRUE)
install.packages("mgcv", dependencies=TRUE)
install.packages("munsell", dependencies=TRUE)
install.packages("nlme", dependencies=TRUE)
install.packages("nnet", dependencies=TRUE)
install.packages("permute", dependencies=TRUE)
install.packages("pheatmap", dependencies=TRUE)
install.packages("plyr", dependencies=TRUE)
install.packages("proto", dependencies=TRUE)
install.packages("RColorBrewer", dependencies=TRUE)
install.packages("Rcpp", dependencies=TRUE)
install.packages("reshape2", dependencies=TRUE)
install.packages("rgl", dependencies=TRUE)
install.packages("rpart", dependencies=TRUE)
install.packages("scales", dependencies=TRUE)
install.packages("scatterplot3d", dependencies=TRUE)
install.packages("slam", dependencies=TRUE)
install.packages("som", dependencies=TRUE)
install.packages("sp", dependencies=TRUE)
install.packages("spatial", dependencies=TRUE)
install.packages("stringr", dependencies=TRUE)
install.packages("survival", dependencies=TRUE)
install.packages("vegan", dependencies=TRUE)
install.packages("wordcloud", dependencies=TRUE)

perlのインストール

anyenvのインストール

brew install anyenv
echo 'eval "$(anyenv init -)"' >> ~/.bash_profile
exec $SHELL -l
anyenv install --init

anyenvのPluginのインストール

mkdir -p ~/.anyenv/plugins #anyenvのプラグインをインストールする「plugins」ディレクトリの作成

git clone https://github.com/znz/anyenv-update.git ~/.anyenv/plugins/anyenv-update
#anyenv updateコマンドでanyenvで入れた**env系の全てをアップデートしてくれるプラグイン

git clone https://github.com/znz/anyenv-git.git ~/.anyenv/plugins/anyenv-git
#anyenv gitコマンドでanyenvで入れた**env系の全てのgitコマンドを実行するプラグイン

plenv

anyone install plenv
exec  $SHELL -l

perlのインストール

plenv install (インストールしたいperl-version)
exec  $SHELL -l
plenv global (インストールしたperl-version)

cpanmをインストール

plenv install-cpanm
exec  $SHELL -l

cpanモジュールをアンインストール

cpanm Unicode::Japanese
exec  $SHELL -l

後はKH-coderに必要なもの(https://github.com/ko-ichi-h/khcoder/issues/91 )をただインストールするだけ

cpanm Jcode*
cpanm Tk*
cpanm DBI
cpanm DBD::CSV (allow testing, say “y”)
cpanm File::BOM*
cpanm Lingua::JA::Regular::Unicode (needs sudo)*
cpanm Net::Telnet
cpanm Excel::Writer::XLSX
cpanm DBD::mysql
cpanm Spreadsheet::ParseExcel::FmtJapan
cpanm Spreadsheet::ParseXLSX
cpanm Statistics::ChisqIndep*
cpanm Statistics::Lite*
cpanm Unicode::Escape*
cpanm Algorithm::NaiveBayes*
cpanm Lingua::Sentence*
cpanm Proc::Background

このperlパッケージをインストールするところが準備段階で一番ハマる(私はPCのデータを全て吹き飛ばしたw)。

以下ハマったこと(cpanm)

cpanm DBD::mysql

とした時に以下のエラーメッセージが出た

Can't link/include C library 'ssl', 'crypto', aborting.

このサイト( https://blog.mitsuto.com/macos-mojave-perl-dbd-mysql )を参考にして、以下のように対応した

cpanm DBD::mysql --configure-args="--libs='-L/usr/local/opt/openssl/lib -lssl -lcrypto -L/usr/local/lib -lmysqlclient'"

KH-coderのインストール

git clone https://github.com/ko-ichi-h/khcoder.git

KH-coder起動

mysql起動

ターミナルからmysqlを起動する

mysql.server start mysql
mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.22 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET GLOBAL local_infile=on; #これがないとmysqlに接続できないエラーが起きる
Query OK, 0 rows affected (0.00 sec)
SET GLOBAL local_infile=on; 

KH-coder 起動

configにあるconfig.iniを以下のように書き換える

sql_username    root
sql_password    #今回は設定しなかった

XQuartzを起動し、KH-coderのkh_coder.plのある場所に移動する。

cd (kh_coder.plのある場所)
perl kh_coder.pl

プロジェクトの設定を開き以下の画面が出てくる
スクリーンショット 2020-10-26 23.31.49.png

日本語がMeCabしか使えない上(少なくとも茶筌が見つからなかった)、辞書コードはutf-8であるため
utf-8
と設定する

Stanford POS Taggerの設定を開き
.jarファイル、.taggerファイルを設定する

後はKH-coderの公式のチュートリアルデータ(https://khcoder.net/tutorial.html )でどのエラー画面が起きるかテストする。

日本語入力について

XQuartzは日本語を入力できないため、適当なテキストエディタに日本語を書き、ctr+vで貼り付ける。

最後に

KH-coderを使うときはWindowsでやろう。絶対それが楽。

参考にしたもの

KH-coder公式

KH-coder GitHub (https://github.com/ko-ichi-h/khcoder)

MacでKH-coderインストールした方々の備忘録

池田大輔氏のMacでのKH Coderのインストール(https://researchmap.jp/blogs/blog_entries/view/75043/1665e5f4b34a161b470604b59bf39e12?frame_id=616670)
@y-urakawa 氏の【Mac】KH Coder導入手順(https://qiita.com/y-urakawa/items/0423bf6775de8e6305f3)

mysql関連

progarteのMySQLの開発環境を用意しよう(macOS)(https://prog-8.com/docs/mysql-env)

mita2db氏のMySQL 8.0 の LOAD DATA で The used command is not allowed with this MySQL version エラー(https://mita2db.hateblo.jp/entry/2020/01/13/163218)

perl関連

@rinpa 氏のanyenv + macOS環境構築(https://qiita.com/rinpa/items/81766cd6a7b23dea9f3c)

@laikuaut 氏のplenvの基本メモ書き(https://qiita.com/laikuaut/items/82c9b402920e30c2c4eb)

みつと氏のmacOS(mojave)にDBD::mysqlをインストールしたいっ!(https://blog.mitsuto.com/macos-mojave-perl-dbd-mysql)

KH-coder module関連

Stanford Pos Tagger(https://nlp.stanford.edu/software/tagger.shtml#About)

11
7
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
11
7