動かざることバグの如し

近づきたいよ 君の理想に

MacOSをSierraにアップデートしたらbundle install nokogiriでコケる

久々にbundle installでコケた

$bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.1.4
Using builder 3.2.3
Using erubi 1.7.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.1
Installing nokogiri 1.8.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/thr3a/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/Users/thr3a/.rbenv/versions/2.3.4/bin/ruby -r ./siteconf20171215-25720-z066a2.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/thr3a/.rbenv/versions/2.3.4/bin/$(RUBY_BASE_NAME)
    --help
    --clean

何もしてないのに・・・とか思ってたけど、よく考えたらMacOSSierraに上げたわ(

OSのアップデート後はコマンドライン開発ツールの更新をしなくてはいけないらしい。

xcode-select --install

した後に

brew install libxml2

すでにインストールしてあった場合はbrew uninstall libxml2して再インストール

これでいけた

Jupyter Notebookでサジェストが出るようにする

残念ながらJupyterのデフォルトだと変数や関数のサジェストが出てこない。

でーたさいえんてぃすとの人たちはこんな辛いものを使っているのかと思っていたが、拡張機能をインストールするとできるようになる

拡張機能のインストール

Jupyter notebook extensionsをインストール

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

拡張機能の有効化

Jupyter Notebookを再起動して、 http://localhost:8888/nbextensions にアクセス

たくさんチェックボックスがあるが、「Hinterland」にチェックを入れる。

するとサジェストが出るようになる。やったね!

PHP + utf8mb4のMySQLにDB接続ができないとき

環境

MySQLに接続できない

PHPからPDO経由でMySQLへ接続しようとしてもうまくいかない。

PDOException: SQLSTATE[HY000] [102] Can't initialize character set utf8mb4 (path: /usr/share/mysql/charsets/) in ****

utf8のDBには正しく接続されるので文字コードが問題っぽいところまではわかったが、そのサーバーからMySQLのコマンド経由だと普通にログインもできるし表示でもできる。むむむ

解決策

どうやらPHPからMySQLに接続するライブラリを変えなきゃいけないらしく、MySQL Native Driverってやつに変えたらいけた

まずは既存のライブラリをアンインストール

yum remove php71w-mysql

MySQL Native Driverのライブラリをインストール

yum install php71w-mysqlnd

service php-fpm restart してphp -mにいればおk

違いは?

今まではlibmysqlclient(MySQL クライアントサーバーライブラリ)が主流だったが、実はPHP 5.3以降はmysqlnd(MySQL ネイティブドライバ)も組み込まれており、今はmysqlndのほうがオススメっぽい。まぁ今時utf8mb4ですし

詳細な比較は公式ドキュメントを参照

http://php.net/manual/ja/mysqlinfo.library.choosing.phpphp.net

参考リンク

Pythonでmake sure the Graphviz executables are on your systems' PATH

環境

エラーの内容

import mglearn
mglearn.plots.plot_animal_tree()

ってやると

ExecutableNotFound: failed to execute ['dot', '-Tpng', '-O', 'tmp'], make sure the Graphviz executables are on your systems' PATH

ってエラーになる。 pip install graphviz は実行済み

対策

graphviz本体?を別途インストールする必要がある

Macなら

brew install graphviz

Ubuntuなら

apt install graphviz
import mglearn
import matplotlib.pyplot as plt
mglearn.plots.plot_animal_tree()
plt.show()

f:id:thr3a:20171210152443p:plain

できた