解决在OS X安装libvips图形库的问题

解决vips库安装失败问题

写在前面:本文列出了问题解决的思路和过程,如果需要直接找到简洁的答案,请(mei)移(ce)步(shi):
http://stackoverflow.com/questions/26195880/libvips-cannot-install-due-to-wrong-python-location

手头上的项目需要在服务器端使用Node.js进行图片处理,一番折腾后找到了gm和lovell/sharp两个库。
由于sharp依赖于libvips,所以尝试在本地的OS中安装先。
按照sharp的提示,执行:

1
brew install homebrew/science/vips --with-webp --with-graphicsmagick

brew工作后开始安装各种依赖先,就在所有依赖包都安装完成后,brew抛出异常:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
==> Installing vips from homebrew/homebrew-science
==> Downloading http://www.vips.ecs.soton.ac.uk/supported/7.40/vips-7.40.11.tar.gz
Already downloaded: /Library/Caches/Homebrew/vips-7.40.11.tar.gz
==> ./configure --prefix=/usr/local/Cellar/vips/7.40.11 --with-magick --with-magickpackage=GraphicsMagick
==> make check
/usr/local/Cellar/gobject-introspection/1.42.0/bin/g-ir-scanner --add-include-path=. --namespace=Vips --nsversion=8.0 --libtool="/bin/sh ../libtool" --include=GObject-2.0 --library=libvips.la --warn-all --verbose --identifier-prefix=Vips --identifier-prefix=vips --symbol-prefix=vips --symbol-prefix=im --symbol-prefix=im_ --cflags-begin -I../libvips/include --cflags-end arithmetic/abs.c arithmetic/add.c arithmetic/arithmetic.c arithmetic/avg.c arithmetic/binary.c arithmetic/boolean.c arithmetic/complex.c arithmetic/deviate.c arithmetic/divide.c arithmetic/getpoint.c arithmetic/hist_find.c arithmetic/hist_find_indexed.c arithmetic/hist_find_ndim.c arithmetic/hough.c arithmetic/hough_circle.c arithmetic/hough_line.c arithmetic/invert.c arithmetic/linear.c arithmetic/math.c arithmetic/math2.c arithmetic/max.c arithmetic/measure.c arithmetic/min.c arithmetic/multiply.c arithmetic/nary.c arithmetic/profile.c arithmetic/project.c arithmetic/relational.c arithmetic/remainder.c arithmetic/round.c arithmetic/sign.c arithmetic/statistic.c arithmetic/stats.c arithmetic/subtract.c arithmetic/sum.c arithmetic/unary.c arithmetic/unaryconst.c cimg/cimg_dispatch.c colour/colour.c colour/colourspace.c colour/dE00.c colour/dE76.c colour/dECMC.c colour/float2rad.c colour/icc_transform.c colour/Lab2LabQ.c colour/Lab2LabS.c colour/Lab2LCh.c colour/Lab2XYZ.c colour/LabQ2Lab.c colour/LabQ2LabS.c colour/LabQ2sRGB.c colour/LabS2Lab.c colour/LabS2LabQ.c colour/LCh2Lab.c colour/LCh2UCS.c colour/rad2float.c colour/scRGB2sRGB.c colour/scRGB2XYZ.c colour/sRGB2scRGB.c colour/UCS2LCh.c colour/XYZ2Lab.c colour/XYZ2scRGB.c colour/XYZ2Yxy.c colour/Yxy2XYZ.c conversion/bandary.c conversion/bandbool.c conversion/bandjoin.c conversion/bandmean.c conversion/bandrank.c conversion/cache.c conversion/cast.c conversion/conversion.c conversion/copy.c conversion/embed.c conversion/extract.c conversion/falsecolour.c conversion/flatten.c conversion/flip.c conversion/gamma.c conversion/grid.c conversion/ifthenelse.c conversion/insert.c conversion/join.c conversion/msb.c conversion/recomb.c conversion/replicate.c conversion/rot.c conversion/rot45.c conversion/scale.c conversion/sequential.c conversion/subsample.c conversion/tilecache.c conversion/wrap.c conversion/zoom.c convolution/compass.c convolution/conv.c convolution/convolution.c convolution/convsep.c convolution/correlation.c convolution/fastcor.c convolution/gaussblur.c convolution/im_aconv.c convolution/im_aconvsep.c convolution/im_conv.c convolution/im_conv_f.c convolution/sharpen.c convolution/spcor.c create/black.c create/buildlut.c create/create.c create/eye.c create/fractsurf.c create/gaussmat.c create/gaussnoise.c create/grey.c create/identity.c create/im_benchmark.c create/invertlut.c create/logmat.c create/mask.c create/mask_butterworth.c create/mask_butterworth_band.c create/mask_butterworth_ring.c create/mask_fractal.c create/mask_gaussian.c create/mask_gaussian_band.c create/mask_gaussian_ring.c create/mask_ideal.c create/mask_ideal_band.c create/mask_ideal_ring.c create/other_dispatch.c create/point.c create/sines.c create/text.c create/tonelut.c create/xyz.c create/zone.c draw/draw.c draw/draw_circle.c draw/draw_flood.c draw/draw_image.c draw/draw_line.c draw/draw_mask.c draw/draw_rect.c draw/draw_smudge.c draw/drawink.c foreign/analyze2vips.c foreign/analyzeload.c foreign/csv.c foreign/csvload.c foreign/csvsave.c foreign/dzsave.c foreign/fits.c foreign/fitsload.c foreign/fitssave.c foreign/foreign.c foreign/jpeg2vips.c foreign/jpegload.c foreign/jpegsave.c foreign/magick2vips.c foreign/magickload.c foreign/matlab.c foreign/matload.c foreign/matrixload.c foreign/matrixsave.c foreign/openexr2vips.c foreign/openexrload.c foreign/openslide2vips.c foreign/openslideload.c foreign/pngload.c foreign/pngsave.c foreign/ppm.c foreign/ppmload.c foreign/ppmsave.c foreign/radiance.c foreign/radload.c foreign/radsave.c foreign/rawload.c foreign/rawsave.c foreign/tiff2vips.c foreign/tiffload.c foreign/tiffsave.c foreign/vips2jpeg.c foreign/vips2tiff.c foreign/vips2webp.c foreign/vipsload.c foreign/vipspng.c foreign/vipssave.c foreign/webp2vips.c foreign/webpload.c foreign/webpsave.c freqfilt/freqfilt.c freqfilt/freqmult.c freqfilt/fwfft.c freqfilt/invfft.c freqfilt/phasecor.c freqfilt/spectrum.c histogram/hist_cum.c histogram/hist_equal.c histogram/hist_ismonotonic.c histogram/hist_local.c histogram/hist_match.c histogram/hist_norm.c histogram/hist_plot.c histogram/hist_unary.c histogram/histogram.c histogram/maplut.c histogram/percent.c histogram/stdif.c iofuncs/base64.c iofuncs/buf.c iofuncs/buffer.c iofuncs/cache.c iofuncs/enumtypes.c iofuncs/error.c iofuncs/gate.c iofuncs/generate.c iofuncs/header.c iofuncs/image.c iofuncs/init.c iofuncs/mapfile.c iofuncs/memory.c iofuncs/object.c iofuncs/operation.c iofuncs/rect.c iofuncs/region.c iofuncs/semaphore.c iofuncs/sink.c iofuncs/sinkdisc.c iofuncs/sinkmemory.c iofuncs/sinkscreen.c iofuncs/system.c iofuncs/threadpool.c iofuncs/type.c iofuncs/util.c iofuncs/vector.c iofuncs/vips.c iofuncs/vipsmarshal.c iofuncs/window.c morphology/countlines.c morphology/hitmiss.c morphology/labelregions.c morphology/morph.c morphology/morphology.c morphology/rank.c mosaicing/global_balance.c mosaicing/im_avgdxdy.c mosaicing/im_chkpair.c mosaicing/im_clinear.c mosaicing/im_improve.c mosaicing/im_initialize.c mosaicing/im_lrcalcon.c mosaicing/im_lrmerge.c mosaicing/im_lrmosaic.c mosaicing/im_remosaic.c mosaicing/im_tbcalcon.c mosaicing/im_tbmerge.c mosaicing/im_tbmosaic.c mosaicing/match.c mosaicing/merge.c mosaicing/mosaic.c mosaicing/mosaic1.c mosaicing/mosaicing.c resample/affine.c resample/interpolate.c resample/quadratic.c resample/resample.c resample/shrink.c resample/similarity.c resample/transform.c video/im_video_test.c video/video_dispatch.c include/vips/basic.h include/vips/vips.h include/vips/object.h include/vips/image.h include/vips/error.h include/vips/foreign.h include/vips/interpolate.h include/vips/header.h include/vips/operation.h include/vips/enumtypes.h include/vips/arithmetic.h include/vips/conversion.h include/vips/type.h libvips.la --output Vips-8.0.gir
/bin/sh: /usr/local/Cellar/gobject-introspection/1.42.0/bin/g-ir-scanner: /usr/local/opt/python/bin/python: bad interpreter: No such file or directory
make[2]: *** [Vips-8.0.gir] Error 126
make[1]: *** [check-recursive] Error 1
make: *** [check-recursive] Error 1
READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
https://github.com/homebrew/homebrew-science/issues

好长的错误信息,不过DEBUG时候要有明(xian)察(de)秋(dan)毫(teng)的耐心,终于发现真正的错误信息在最后(⊙o⊙)…

1
/bin/sh: /usr/local/Cellar/gobject-introspection/1.42.0/bin/g-ir-scanner: /usr/local/opt/python/bin/python: bad interpreter: No such file or directory

于是第一时间把/usr/local/Cellar/gobject-introspection/黏贴到chrome中想去google上找答案,回车后发现chrome竟然直接在页面显示上面的路径,才想起来这是多合一的搜索框的好(huai)处,以后可以直接拿浏览器当finder用了。

顺着路径找到了名字叫 g-ir-scanner 的这个文档。发现这个shell程序需要python来执行了,怀疑是不是之前的python安装有问题(虽然对python没大了解,但是感觉其版本让人眼花缭乱的)。
which了一下python果然不在/usr/local/opt下面,方才断定是python安装的问题。

上google查找了一堆相关页面也没发现有直接的解决办法。决定按照brew给出了类似提示解决:

1
2
3
4
5
6
7
8
9
10
➜ ~ brew info python
python: stable 2.7.8 (bottled), HEAD
https://www.python.org
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/python.rb
==> Dependencies
Build: pkg-config ✔
Required: openssl ✘
Recommended: readline ✘, sqlite ✘, gdbm ✔
...

Oh-my, python果然没有’安装’,想起来之前用的一直是OS X提供的native版本。

1
2
3
4
5
6
7
8
9
10
➜ ~ brew info gobject-introspection
gobject-introspection: stable 1.42.0 (bottled)
http://live.gnome.org/GObjectIntrospection
/usr/local/Cellar/gobject-introspection/1.42.0 (196 files, 10M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/gobject-introspection.rb
==> Dependencies
Build: xz ✔, pkg-config ✔
Required: glib ✔, libffi ✔
==> Options

但是可以看出gobject-introspection的formula并没有把python列为Required。但是安装vips时候似乎又需要python,所以会出上面的问题╮(╯▽╰)╭

好了,现在解决办法是重新安装一下gobject-introspection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
➜ ~ brew reinstall gobject-introspection
==> Reinstalling gobject-introspection
==> Installing dependencies for gobject-introspection: readline, sqlite, openssl, python
==> Installing gobject-introspection dependency: readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.3.8.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.3.8.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.
OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/readline/lib
CPPFLAGS: -I/usr/local/opt/readline/include
==> Summary
🍺 /usr/local/Cellar/readline/6.3.8: 40 files, 2.1M
==> Installing gobject-introspection dependency: sqlite
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/sqlite-3.8.7.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring sqlite-3.8.7.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
OS X provides an older sqlite3.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/sqlite/lib
CPPFLAGS: -I/usr/local/opt/sqlite/include
==> Summary
🍺 /usr/local/Cellar/sqlite/3.8.7: 9 files, 2.1M
==> Installing gobject-introspection dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1j.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.1j.mavericks.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
==> Summary
🍺 /usr/local/Cellar/openssl/1.0.1j: 431 files, 15M
==> Installing gobject-introspection dependency: python
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/python-2.7.8_2.mavericks.bottle.3.tar.gz
######################################################################## 100.0%
==> Pouring python-2.7.8_2.mavericks.bottle.3.tar.gz
==> Caveats
Setuptools and Pip have been installed. To update them
pip install --upgrade setuptools
pip install --upgrade pip
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python
.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.
==> /usr/local/Cellar/python/2.7.8_2/bin/python -s setup.py --no-user-cfg install --force --verbose --install-scripts=/u
==> /usr/local/Cellar/python/2.7.8_2/bin/python -s setup.py --no-user-cfg install --force --verbose --install-scripts=/u
==> Summary
🍺 /usr/local/Cellar/python/2.7.8_2: 4776 files, 76M
==> Installing gobject-introspection
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gobject-introspection-1.42.0.mavericks.bottle.1.tar
Already downloaded: /Library/Caches/Homebrew/gobject-introspection-1.42.0.mavericks.bottle.1.tar.gz
==> Pouring gobject-introspection-1.42.0.mavericks.bottle.1.tar.gz
🍺 /usr/local/Cellar/gobject-introspection/1.42.0: 196 files, 10M

然后再重复之前的libvips安装命令:

1
2
3
4
5
6
7
8
➜ ~ brew install homebrew/science/vips --with-webp --with-graphicsmagick
==> Installing vips from homebrew/homebrew-science
==> Downloading http://www.vips.ecs.soton.ac.uk/supported/7.40/vips-7.40.11.tar.gz
Already downloaded: /Library/Caches/Homebrew/vips-7.40.11.tar.gz
==> ./configure --prefix=/usr/local/Cellar/vips/7.40.11 --with-magick --with-magickpackage=GraphicsMagick
==> make check
==> make install
🍺 /usr/local/Cellar/vips/7.40.11: 196 files, 13M, built in 82 seconds

终于问题得到了解决,剩下的就是驱动sharp了。

Let’s coding!

写在后面:解决这一个问题大概花费了3个半小时,无奈咱的网路环境就是name非比寻常!连Xcode都没法直接更新。