Difference between 'require 'rmagick' and 'require RMagick' (Mac vs Debian)

对着背影说爱祢 提交于 2019-12-01 11:46:17

The root cause of this it that the filesystem on Mac OS X is case insensitive by default. You can do a quick test to confirm this if you want on the command line.

touch testcase
touch Testcase
ls

If you only see only one testcase file then your probably on a case insensitive fs. Alternatively you can do something like:

diskutil info /

In the result if you see

File System Personality: Journaled HFS+ 

and not

File System Personality: Case-sensitive Journaled HFS+.

then your case insensitive. If your insensitive then that is what allows you to get away with requiring 'RMagick' or 'rmagick' or any other capitalization pattern. As Cameron points out the lib file that your including is capitalized see: https://github.com/rmagick/rmagick/blob/master/lib/RMagick.rb This means that when you are on a case sensitive fs you will have to

require 'RMagick'

as

require 'rmagick'

looks for a file that does not exist.

I have seen a lot of issues with this especially if your git repo has two files with the same name and different cases in the same folder (for me this results in git always reporting uncommitted changes). For what its worth I used disk utility to create case sensitive disk image that I mount and use for development. That way I can leave the default case insensitive fs in place and avoid annoying issues like this.

require 'RMagick'

is what you should be using. if that is not working on OSX, something is not right with your installation. what does your Gemfile look like?

RMagick

My setup is a Mac development system using RubyMine and deploying to an Ubuntu server using capistrano. I kept getting a failure during deployment even though I was certain the remote system had the correct imagemagick libraries on it.

The error message during cap deploy was

cannot load such file -- rmagick

Ubuntu and Mac Gemfile

gem 'rmagick'

require 'RMagick' OS X

The issue I have found is that the development of a rails rake on Mac OS X will allow you to get away with

require 'rmagick'

OR

require 'RMagick'

require 'RMagick' Ubuntu

Where previously I had installed and tested the library:

sudo apt-get install libmagickwand-dev
gem install rmagick

The lowercase rmagick didn't work, confusing since it was working, which leads you to the conclusion that you have a library issue. However, the issue is the require line.

require 'RMagick'

Conclusion

Always use RMagick for the require line, because that is the official name of the library.

On Mac OSX, you must install the these from source:

brew install imagemagick --disable-openmp --build-from-source

sudo gem install rmagick

Taken from this post:

http://blog.paulopoiati.com/2013/01/28/installing-rmagick-in-mac-os-x-mountain-lion-with-homebrew/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!