Ruby Gem - 加载错误

发布于 2024-10-01 14:44:38 字数 2404 浏览 6 评论 0原文

Ruby 新手试图弄清楚如何使用 Gem,但到目前为止,体验并不是那么好。

通过 gem 安装 mysql2 后,我尝试在一个简单的文件中使用它。

require 'mysql2'

#client = Mysql2::Client.new(:host => "localhost", :username => "username")

虽然当我运行这个时,我得到:

Parse.rb:1:in `require': no such file to load -- mysql2 (LoadError)
 from Parse.rb:1

然而我的gem列表包含mysql2:

Tanner-Smiths-MacBook-Pro:Humans_vs_Zombies_Parse tanner$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.1, 2.3.5, 1.3.6)
actionpack (3.0.1, 2.3.5, 1.13.6)
actionwebservice (1.2.6)
activemodel (3.0.1)
activerecord (3.0.1, 2.3.5, 1.15.6)
activeresource (3.0.1, 2.3.5)
activesupport (3.0.1, 2.3.5, 1.4.4)
acts_as_ferret (0.4.3)
arel (2.0.2)
builder (2.1.2)
capistrano (2.5.19, 2.5.2)
cgi_multipart_eof_fix (2.5.0)
daemons (1.1.0, 1.0.10)
dnssd (1.4, 0.6.0)
erubis (2.6.6)
fastthread (1.0.7, 1.0.1)
fcgi (0.8.8, 0.8.7)
ferret (0.11.6)
gem_plugin (0.2.3)
highline (1.6.1, 1.5.0)
hpricot (0.8.3, 0.6.164)
i18n (0.4.2)
jk-ferret (0.11.8.2)
libxml-ruby (1.1.4, 1.1.2)
mail (2.2.9)
mime-types (1.16)
mongrel (1.1.5)
mysql2 (0.2.6)
needle (1.3.0)
net-scp (1.0.4, 1.0.1)
net-sftp (2.0.5, 2.0.1, 1.1.1)
net-ssh (2.0.23, 2.0.4, 1.1.4)
net-ssh-gateway (1.0.1, 1.0.0)
polyglot (0.3.1)
rack (1.2.1, 1.0.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (2.3.5, 1.2.6)
railties (3.0.1)
rake (0.8.7, 0.8.3)
RedCloth (4.2.3, 4.1.1)
ruby-openid (2.1.8, 2.1.2)
ruby-yadis (0.3.4)
rubynode (0.1.5)
sqlite3-ruby (1.3.2, 1.2.4)
termios (0.9.4)
thor (0.14.4)
treetop (1.4.8)
tzinfo (0.3.23)
xmpp4r (0.5, 0.4)

“ruby env”的结果:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/tanner/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/

我在这里做错了什么?我想不通。

谢谢

-坦纳

Ruby newbie here trying to figure out how to use a Gem and thus far the experience is not that great.

After installing mysql2 via gem I tried to use it in a simple file.

require 'mysql2'

#client = Mysql2::Client.new(:host => "localhost", :username => "username")

Though when I run this I get:


Parse.rb:1:in `require': no such file to load -- mysql2 (LoadError)
 from Parse.rb:1

Yet my gem list contains mysql2:

Tanner-Smiths-MacBook-Pro:Humans_vs_Zombies_Parse tanner$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.1, 2.3.5, 1.3.6)
actionpack (3.0.1, 2.3.5, 1.13.6)
actionwebservice (1.2.6)
activemodel (3.0.1)
activerecord (3.0.1, 2.3.5, 1.15.6)
activeresource (3.0.1, 2.3.5)
activesupport (3.0.1, 2.3.5, 1.4.4)
acts_as_ferret (0.4.3)
arel (2.0.2)
builder (2.1.2)
capistrano (2.5.19, 2.5.2)
cgi_multipart_eof_fix (2.5.0)
daemons (1.1.0, 1.0.10)
dnssd (1.4, 0.6.0)
erubis (2.6.6)
fastthread (1.0.7, 1.0.1)
fcgi (0.8.8, 0.8.7)
ferret (0.11.6)
gem_plugin (0.2.3)
highline (1.6.1, 1.5.0)
hpricot (0.8.3, 0.6.164)
i18n (0.4.2)
jk-ferret (0.11.8.2)
libxml-ruby (1.1.4, 1.1.2)
mail (2.2.9)
mime-types (1.16)
mongrel (1.1.5)
mysql2 (0.2.6)
needle (1.3.0)
net-scp (1.0.4, 1.0.1)
net-sftp (2.0.5, 2.0.1, 1.1.1)
net-ssh (2.0.23, 2.0.4, 1.1.4)
net-ssh-gateway (1.0.1, 1.0.0)
polyglot (0.3.1)
rack (1.2.1, 1.0.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (2.3.5, 1.2.6)
railties (3.0.1)
rake (0.8.7, 0.8.3)
RedCloth (4.2.3, 4.1.1)
ruby-openid (2.1.8, 2.1.2)
ruby-yadis (0.3.4)
rubynode (0.1.5)
sqlite3-ruby (1.3.2, 1.2.4)
termios (0.9.4)
thor (0.14.4)
treetop (1.4.8)
tzinfo (0.3.23)
xmpp4r (0.5, 0.4)

Results of "ruby env":

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-10
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/tanner/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/

What am I doing wrong here? I can't figure it out.

Thanks

-Tanner

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小矜持 2024-10-08 14:44:38

您可能已经注意到,您安装了多个版本的 ruby​​。我强烈建议您使用 RVM 来管理多个 ruby​​ 版本。

这是一个大胆的猜测,但如果您不使用命令行来运行应用程序并使用 TextMate 等工具,您可能需要设置一个 shell 变量“TM_RUBY”以指向已安装 ruby​​gems 的 ruby​​ 版本(1.8.7 (2009-06-12 补丁级别 174))。

您可以尝试:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/irb

获取安装了 ruby​​gems 的 irb 版本,然后尝试:

require 'rubygems'
require 'mysql2'

如果这有效并且您对此感到满意,您可以更新 /usr/bin/ruby、/usr/bin/irb、/ 中的符号链接usr/bin/gem 指向旧版本的 ruby​​ 或再次安装 RVM,让您的生活变得更加轻松。

As you probably noticed, you have multiple versions of ruby installed. I strongly recommand you using RVM to manage multiple ruby versions.

It is a wild guess but if you aren't using the command line to run your application and using a tools such as TextMate you might need set a shell variable "TM_RUBY" to point to the ruby version with the installed rubygems (1.8.7 (2009-06-12 patchlevel 174)).

You can try:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/irb

to get to the irb version with the rubygems installed and than try:

require 'rubygems'
require 'mysql2'

If thats work and you are happy with that you could either update you symbolic links in /usr/bin/ruby, /usr/bin/irb, /usr/bin/gem to point to the older version of ruby or once again install RVM and make your life much easier.

静待花开 2024-10-08 14:44:38

尝试:

require 'rubygems'
require 'mysql2'

Try:

require 'rubygems'
require 'mysql2'
夏末 2024-10-08 14:44:38

要获取更多信息,请启动 irb 并运行:

require 'rubygems'
gem 'mysql2'  #=> does this cause an error?
$:.grep /mysql2/  #=> if no error from previous line, please post what this shows

同样在终端提示符下,运行“gemcontentsmysql2”。
您是否看到以下结尾的路径?

lib/mysql2/error.rb
lib/mysql2/mysql2.bundle
lib/mysql2/client.rb
lib/mysql2/result.rb
lib/mysql2.rb

To get more info, start up irb and run:

require 'rubygems'
gem 'mysql2'  #=> does this cause an error?
$:.grep /mysql2/  #=> if no error from previous line, please post what this shows

Also at the terminal prompt, run "gem contents mysql2".
Do you see paths ending with the following?

lib/mysql2/error.rb
lib/mysql2/mysql2.bundle
lib/mysql2/client.rb
lib/mysql2/result.rb
lib/mysql2.rb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文