Ubuntu 20.04下RMagick初始化报错:无法加载rvg/rvg求助
问题描述
环境信息
- 系统:Ubuntu 20.04
- Ruby版本:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux] - Gem版本:
gem --version 3.1.4 - ImageMagick版本:
convert --version Version: ImageMagick 6.9.10-23 Q16 x86_64
已执行操作
- 安装依赖包:
sudo apt-get install libmagickwand-dev - 成功通过sudo安装RMagick:
sudo gem install rmagick Building native extensions. This could take a while... Successfully installed rmagick-4.2.6 Parsing documentation for rmagick-4.2.6 Done installing documentation for rmagick after 0 seconds 1 gem installed - 运行pheno_gram命令:
ruby pheno_gram.rb -i phenogram-sample.txt -g human_genome.txt -Y cytoBand-human.txt -c exhaustive -p proximity -f png -p equal -o plot_phenogram -t "New Image" - 尝试通过snap安装rvg库(失败):
sudo snap install hello-rvg --candidate - 尝试无sudo安装RMagick(失败):
gem install rmagick Building native extensions. This could take a while... ERROR: Error installing rmagick: ERROR: Failed to build gem native extension. current directory: /home/super/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rmagick-4.2.6/ext/RMagick /home/super/.rbenv/versions/2.7.2/bin/ruby -I /home/super/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20220827-10097-72cju5.rb extconf.rb checking for brew... no checking for pacman... yes checking for Ruby version >= 2.3.0... yes checking for pkg-config... yes checking for outdated ImageMagick version (<= 6.7.7)... no checking for /home/super/miniconda3/bin/x86_64-conda-linux-gnu-cc... yes *** 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=/home/super/.rbenv/versions/2.7.2/bin/$(RUBY_BASE_NAME) /home/super/.rbenv/versions/2.7.2/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /home/super/.rbenv/versions/2.7.2/lib/ruby/2.7.0/mkmf.rb:564:in `try_link0' from /home/super/.rbenv/versions/2.7.2/lib/ruby/2.7.0/mkmf.rb:582:in `try_link' from extconf.rb:79:in `configure_compile_options' from extconf.rb:19:in `initialize' from extconf.rb:405:in `new' from extconf.rb:405:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/super/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/rmagick-4.2.6/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /home/super/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rmagick-4.2.6 for inspection. Results logged to /home/super/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/rmagick-4.2.6/gem_make.out
遇到的错误
- 运行pheno_gram时报错:
cannot load such file -- rvg/rvg Please install RMagick -- See documentation for pheno_gram or http://rmagick.rubyforge.org/install-faq.html - 无sudo安装RMagick时,提示缺少开发工具,无法编译原生扩展。
解决方案
1. 解决rvg依赖问题
报错找不到rvg/rvg是因为需要安装rvg gem,而非snap包,执行以下命令:
sudo gem install rvg
如果使用rbenv管理Ruby,安装后需刷新环境:
rbenv rehash
2. 解决无sudo安装RMagick失败的问题
先安装Ubuntu基础编译工具包:
sudo apt-get install build-essential
由于你使用了miniconda,可能存在编译器路径冲突,安装时指定系统编译器:
CC=/usr/bin/gcc gem install rmagick
或者暂时禁用conda环境后再安装:
conda deactivate gem install rmagick
3. 验证依赖加载
安装完成后,在Ruby控制台测试是否能正常加载依赖:
irb require 'rmagick' require 'rvg/rvg'
若没有报错,说明依赖加载正常,可重新运行pheno_gram命令。
内容的提问来源于stack exchange,提问作者Waqas Khokhar
相关产品推荐
相关产品推荐

