2013-02-12 96 views
5

当我尝试运行“包安装”,我得到一个奇怪的错误:“无效的字节序列在US-ASCII(引发ArgumentError)”捆绑安装错误“在US-ASCII无效字节序列(引发ArgumentError)”

$ bundle install 
    Updating git://github.com/devton/catarse_paypal_express.git 
    Unfortunately, a fatal error has occurred. Please see the Bundler 
    troubleshooting documentation at http://bit.ly/bundler-issues. Thanks! 
    /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler.rb:294:in `block in load_gemspec_uncached': invalid byte sequence in US-ASCII (ArgumentError) 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler.rb:291:in `chdir' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler.rb:291:in `load_gemspec_uncached' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler.rb:282:in `load_gemspec' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:411:in `block in load_spec_files' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:410:in `each' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:410:in `load_spec_files' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:799:in `load_spec_files' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:381:in `local_specs' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/source.rb:774:in `specs' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:491:in `block in converge_locked_specs' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:480:in `each' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:480:in `converge_locked_specs' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:166:in `resolve' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:113:in `specs' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/definition.rb:108:in `resolve_remotely!' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/installer.rb:81:in `run' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/installer.rb:14:in `install' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/cli.rb:230:in `install' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/vendor/thor/task.rb:27:in `run' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/vendor/thor.rb:275:in `dispatch' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/vendor/thor/base.rb:408:in `start' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/bin/bundle:14:in `block in <top (required)>' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/lib/bundler/friendly_errors.rb:4:in `with_friendly_errors' 
     from /Users/.../.rvm/gems/[email protected]/gems/bundler-1.2.3/bin/bundle:14:in `<top (required)>' 
     from /Users/.../.rvm/gems/[email protected]/bin/bundle:19:in `load' 
     from /Users/.../.rvm/gems/[email protected]/bin/bundle:19:in `<main>' 
     from /Users/.../.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval' 
     from /Users/.../.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>' 

我发现这种解决方法(这为我的作品):

if RUBY_VERSION =~ /1.9/ 
    Encoding.default_external = Encoding::UTF_8 
    Encoding.default_internal = Encoding::UTF_8 
end 

但我觉得,以后,所以我宁可不使用它,只是试着去了解什么是真正的错在这里它会导致不同的错误。 我肯定知道这个相同的代码工作在不同的系统...

回答

15

作为一种变通方法,您可以设置UTF8区域设置在您的系统:

export LANG="C.UTF-8" 
export LC_ALL="C.UTF-8" 

关于这方面更多的信息是here

+0

这就是事情 - 我不想要解决方法,我想了解问题的原因并解决问题。 – Rizon 2013-02-12 19:26:16

+1

没有查看确切的文件(在这种情况下,gemspec)我不能肯定地说,但最可能的原因是该文件使用utf8编码,但Ruby正在尝试读取文件并假定它使用ASCII编码。你无法解决这个问题,因此处理它的最好方法是使用解决方法,它告诉ruby假定默认值是utf8。 – Tomdarkness 2013-02-12 21:30:30

+0

@Rizon我已经更新了答案,并附有捆绑商问题的链接 – 2013-02-13 07:18:46