rmagick libMagickCore.5.dylib (LoadError)

rmagickをインストールしてもインストールした情報が読み込まれずに結構はまってしまいました

解決方法

まずはrmagickをアンインストールします
その後、bundle installして以下のような画面が出てこればおっけーです!

$ rbenv global system
$ gem list 
$ sudo gem uninstall rmagick
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Rubygems 2.0.14.1 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Using rake 10.5.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using rack 1.5.5
Using mime-types 2.99
Using arel 5.0.1.20140414130214
Using debug_inspector 0.0.2
Using byebug 8.2.2
Using coderay 1.1.0
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using deep_merge 1.0.1
Using daemons 1.2.3
Using hike 1.2.3
Using multi_json 1.11.2
Using kgio 2.10.0
Using method_source 0.8.2
Using mini_portile2 2.0.0
Using multipart-post 2.0.0
Using pg 0.18.4
Using phantomjs 1.9.8.0
Using slop 3.6.0
Using yard 0.8.7.6
Using bundler 1.13.7
Using tilt 1.4.1
Using raindrops 0.15.0


Your user account isn't allowed to install to the system Rubygems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to Rubygems using sudo.

  Password: 
Installing rmagick 2.14.0 with native extensions
Using sass 3.2.19
Using spring 1.6.3
Using sqlite3 1.3.11
Using rdoc 4.2.1
Using tzinfo 1.2.2
Using rack-test 0.6.3
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using nokogiri 1.6.7.2
Using pry 0.10.3
Using sprockets 2.12.4
Using unicorn 5.0.1
Using sdoc 0.4.1
Using activesupport 4.1.14.1
Using pry-byebug 3.3.0
Using pry-doc 0.8.0
Using pry-rails 0.3.4
Using pry-stack_explorer 0.4.9.2
Using actionview 4.1.14.1
Using activemodel 4.1.14.1
Using config 1.0.0
Using delayed_job 4.1.1
Using jbuilder 2.4.0
Using actionpack 4.1.14.1
Using activerecord 4.1.14.1
Using actionmailer 4.1.14.1
Using railties 4.1.14.1
Using sprockets-rails 2.3.3
Using delayed_job_active_record 4.1.0
Using coffee-rails 4.0.1
Using jquery-rails 3.1.4
Using rails 4.1.14.1
Using sass-rails 4.0.5
Bundle complete! 22 Gemfile dependencies, 67 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

参考にした記事

解決に導いてくれた記事

How can I correctly uninstall gems from OSX’s system ruby 1.8.x while using rbenv + different ruby version?

試したこと一覧の記事

ImageMagick unable to start because of incompatible version of liblzma

RMagick complaining about libMagickCore.5.dylib not found in OSX
Rails – Can’t install RMagick 2.16.0. Can’t find MagickWand.h
RMagick installation: Can’t find MagickWand.h
Can’t install RMagick 2.13.1. Can’t find MagickWand.h.
RMagick errors when running Rake Tasks in OS X Maverick
Mountain Lionにアップグレード後にRMagickがエラーになる場合の対応
rmagickのインストールに失敗したときの対処方法
Library not loaded: /usr/local/lib/libMagickCore.4.dylib (LoadError) #9

warning: already initialized constant APP_PATH #259

bin/rails:6: warning: already initialized constant APP_PATH

bundle install rmagickエラー

OSのアップデートやbrew のアップデートした後からいろいろなところでエラーが出てきて
結構時間使っちゃいました

最終的に参考にしたサイトにたどり着くまでにかなりの時間を要したので
できればリンクを拡散してくれるとありがたいです

[toc]

一番スタンダードなエラー

問題点は

  • imagemagickのバージョン
  • MagickWand.h.のパス

などですね

このエラーはいろいろなところで共有されているので、
「imagemagick Magickwand.h path」 的な感じで調べれば比較的簡単に見つかるかと

こちらが参考にした記事

bundle install “rmagick” でインストールができない
Can’t install RMagick 2.13.1. Can’t find MagickWand.h.

Can't install RMagick 2.13.4. Can't find MagickWand.h.
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby


Gem files will remain installed in
/Users/Masahiro/crowdworks/compass/vendor/bundle/ruby/2.0.0/gems/rmagick-2.13.4 for inspection.
Results logged to
/Users/Masahiro/crowdworks/compass/vendor/bundle/ruby/2.0.0/gems/rmagick-2.13.4/ext/RMagick/gem_make.out

An error occurred while installing rmagick (2.13.4), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.4'` succeeds before bundling.

no を連発してくるエラー

ひたすら no を連発してくるので何が原因で
どこをさわればいいかわからずここで苦戦をしいられました

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for xcrun... yes
checking for Magick-config... yes

Warning: Found more than one ImageMagick installation. This could cause problems at runtime.
/usr/local/opt/imagemagick@6/bin/Magick-config reports version 6.9.8 Q16 is installed in
/usr/local/Cellar/imagemagick@6/6.9.8-3
/usr/local/bin/Magick-config reports version 6.9.8 Q16 is installed in
/usr/local/Cellar/imagemagick@6/6.9.8-3
Using 6.9.8 Q16 from /usr/local/Cellar/imagemagick@6/6.9.8-3.

checking for ImageMagick version >= 6.4.9... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... yes
checking for snprintf() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AcquireImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for AffinityImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for AffinityImages() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for AutoGammaImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for AutoLevelImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for BlueShiftImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for ColorMatrixImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for ConstituteComponentTerminus() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for DeskewImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for DestroyConstitute() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for EncipherImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for EqualizeImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for EvaluateImages() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for FloodfillPaintImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for FunctionImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for GetAuthenticIndexQueue() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for GetAuthenticPixels() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for GetImageAlphaChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for GetMagickFeatures() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for GetVirtualPixels() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for LevelImageColors() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for LevelColorsImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for LevelizeImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for LiquidRescaleImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for MagickLibAddendum() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for OpaquePaintImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for QueueAuthenticPixels() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for RemapImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for RemapImages() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for RemoveImageArtifact() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for RotationalBlurImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for RotationalBlurImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SelectiveBlurImageChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SetImageAlphaChannel() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SetImageArtifact() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SetMagickMemoryMethods() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SparseColorImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for StatisticImage() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for SyncAuthenticPixels() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for TransformImageColorspace() in
assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... no
checking for TransparentPaintImage() in

4時間ぐらいかかっちゃいましたけど、全く同じ状況のエラー記事を見つけましたので
試してみたところ、その後のbundle installでエラーが出てしまうので

$ ARCHFLAGS="-arch x86_64" gem install rmagick -v '2.13.4'

bundle installで実行してみたら無事にできました!!

$  sudo ARCHFLAGS="-arch x86_64" bundle install

参考にした記事

Error Installing therubyracer, v8 on OS X EI Capitan

bundle install pgでのエラー

postgre使ってないのでなんでエラーが出たかわかんないですけど、
とりあえず以下のコードで対処できました

$ bundle install --without production --path vendor/bundle

エラー内容

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
	--with-pg
	--without-pg
	--enable-windows-cross
	--disable-windows-cross
	--with-pg-config
	--without-pg-config
	--with-pg_config
	--without-pg_config
	--with-pg-dir
	--without-pg-dir
	--with-pg-include
	--without-pg-include=${pg-dir}/include
	--with-pg-lib
	--without-pg-lib=${pg-dir}/
	--with-pqlib
	--without-pqlib
	--with-libpqlib
	--without-libpqlib
	--with-ms/libpqlib
	--without-ms/libpqlib


Gem files will remain installed in
/var/folders/ms/gm848ycn6hd0n4yt41n6hj100000gn/T/bundler20170414-51080-9w9ihqpg-0.18.4/gems/pg-0.18.4
for inspection.
Results logged to
/var/folders/ms/gm848ycn6hd0n4yt41n6hj100000gn/T/bundler20170414-51080-9w9ihqpg-0.18.4/gems/pg-0.18.4/ext/gem_make.out

An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.

参考にした記事

bundle installのpgインストールでエラー

Flask + SQLAlchemy + MySQL

SQLAlchemyを使ったチュートリアルや情報はsqliteばっかりだったのでMySQLの記事を書いてみました〜

一番手っ取り早く使うには

$ pip install pymysql

をインストールして

#  mysql+pymysql://ユーザー名:パスワード@localhost/データベース名
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:@localhost/flask-app'

で接続することができます!

参考にした記事

Switching from SQLite to MySQL with Flask SQLAlchemy
ImportError: No module named MySQLdb

mysqlが接続できない時の対処法

brew update後mysqlに接続することができずに壮絶にはまってしまいました

[toc]

この記事書いている途中で
mysqlのsocketエラーでrailsアプリが起動できない
こちらを発見したので、よければ試してください
socketの権限関連の記事です

解決方法

とりあえずの解決方法です
ちなみにmysqlを削除して再度インストーるするので
大切なデータがある場合はバックアップを取っておくように

# mysqlディレクトリの削除
$ sudo rm -rf /usr/local/var/mysql

# mysqlをアンインストール
$ brew uninstall mysql

$ brew cleanup

# mysqlを再インストール
$ brew install mysql56

# リンクさせる
$ brew link mysql56 --force
If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/mysql@5.6/bin:$PATH"' >> ~/.bash_profile

# パスを追加
$ echo 'export PATH="/usr/local/opt/mysql@5.6/bin:$PATH"' >> ~/.bash_profile

# 動くか確認
$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)

# サーバー起動
$ sudo mysql.server start
Starting MySQL
.Logging to '/usr/local/var/mysql/****.local.err'.
.... SUCCESS! 


# 動いた!!!!!!!!

原因

以前brewを update した際も権限周りでエラーが出てきてmysqlに接続することができないことがありました
正直今回もそれと同じ問題かと思いましたが、何度試しても治らないので最終的に再インストールするという
力技でなんとか終わることができたんですけど、もし原因がわかる方がいらっしゃったら教えていただきたいです

エラーの内容とやった流れは

  • ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

    $ sudo touch /tmp/mysql.sock

    →ダメ

  • ERROR! The server quit without updating PID file (/usr/local/var/mysql/****.local.pid).

    →何やっても対処できなかった

です。

試した方法 + 参考記事

Mac OS X El CapitanでMySQLをクリーンインストールする
MySQL 5.5 を Homebrew でインストールする手順 (Mac OS X)
mysqlが起動しない問題
tweeeetyのぶろぐ的めも

StandardError: An error has occurred, this and all later migrations canceled: undefined method `shop_id’ for

新たにカラムを追加する際、

StandardError: An error has occurred, this and all later migrations canceled:

undefined method `shop_id' for ....

というエラーが出てきました

migration ファイルの中で以下のようにインスタンスを作っていたことが原因でした

Something.create()

参考にした記事
[db:migrate] error on migration – undefined method `file_changed?’ #195
Rake aborted. Migrate aborted. Standard Error. Undefined Method. So what exactly causes this?
rake db:migrate fails when using this gem with mysql #31
Problems with migration, “undefined method `ext’” in Active Record?

rails オススメチュートリアル

[toc]

Web アプリ

2ch

いつかやってみたいと思いつつもなかなかできていないチュートリアルです
個人的に2chを作ってみたいと思っていたので、そのうちやってみたいです

はじめてのRailsアプリ 2chの簡易クローンアプリを作る

API

JWT

JWTを使ってAPIを作成するチュートリアルです

Ruby Authentication: Secure Your Rack Application with JWT

Token based API

一度やったことがあるチュートリアルです
多分勉強になったと思います

Securing an API in Rails 5 using Token Based Authentication

devise token auth

初めて devise token auth を利用する際に参考にした記事です
結構わかりやすくて好きでした

Rails API With Authentication Simple Tutorial

TDD

Build Instagram

こちらはまだやっていないけど、TDDでInstagramのコピーを作るというチュートリアルです
htmlがhamlなので、この機会にやってみてもいいかもと思ってます
ちなみに7つほどのシリーズで、結構量もあるから結構勉強になりそうです

Let’s Build: Instagram (Test Driven with Ruby on Rails) – Part 1