使用Gulp安装canvas时出现cario install命令未找到的问题

3

我是一名对命令行工作比较新的人。我正在使用gulp设置一个项目,并已成功安装gulp并编译sass文件。然而,我无法通过以下方式安装canvas:

$ npm install canvas

我需要安装canvas,因为css-sprite运行需要它。我遇到了以下错误。我已经安装了cairo、quartz和homebrew。我查看了其他问题单并尝试运行export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig,然后重新安装,但没有成功,也不知道还能做什么来解决问题。
以下是错误信息...
npm http GET https://registry.npmjs.org/canvas
npm http 304 https://registry.npmjs.org/canvas
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/nan

canvas@1.1.3 install /usr/local/lib/node_modules/canvas
node-gyp rebuild

./util/has_cairo_freetype.sh: line 4: pkg-config: command not found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0.
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Darwin 13.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/canvas
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm ERR! canvas@1.1.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the canvas@1.1.3 install script.
npm ERR! This is most likely a problem with the canvas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls canvas
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 13.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "canvas"
npm ERR! cwd /Users/kylebebeau/websites/ls/code/templates/ls3
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/kylebebeau/websites/ls/code/templates/ls3/npm-debug.log
npm ERR! not ok code 0

非常感谢您的帮助和指导。

1个回答

2

我也遇到了这个问题。我也使用brew安装了cairo和quartz。我按照这里的说明,尤其是以下步骤解决了我的问题。

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

确保将此添加到您的.bashrc.zshrc文件中,以便在会话之间保持持久。成功编译后,我删除了node_modules目录,并在新终端会话中再次尝试npm install时,我必须重新导出PKG_CONFIG_PATH才能使其再次正确编译。

以下是缩写的输出示例:

$ npm install
> node-gyp rebuild
Package xcb-shm was not found in the pkg-config search path.
Perhaps you should add the directory containing `xcb-shm.pc'
to the PKG_CONFIG_PATH environment variable
Package 'xcb-shm', required by 'cairo', not found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0. while trying to load binding.gyp
gyp ERR! configure error
...

$ export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
$ npm install                            

$ canvas@1.1.3 install $HOME/projects/canvas/node_modules/canvas
$ node-gyp rebuild
...
Successful Compile

npm start 在此时没有错误。

我希望这对任何遇到这种情况的人有所帮助。


1
如果您需要为X11和其他软件包设置PKG_CONFIG_PATH,可以执行以下操作:"export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:/usr/local/bin/pkg-config"这是不可能的吗? - Carlos Saltos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接