(...)在`require'中:没有要加载的文件 - 'gemname'(LoadError)

时间:2023-01-19 13:55:43

I haven been all day training to fix this problem but i couldn't.

我一整天都在训练解决这个问题,但我不能。

The question is easy, i don't want to put anymore the require 'rubygems' line everytime i require a gem...

问题很简单,我不想再每次需要宝石时都要求'rubygems'线...

If i put the require 'rubygems' before any other "require" the file runs perfect but if i don't put the require 'rubygems' line the following error occurs:

如果我在任何其他“require”之前放置require'rubygems'文件运行完美但如果我没有把require'rubygems'行,则会出现以下错误:

(...)in `require': no such file to load -- 'gemname' (LoadError)

(...)在`require'中:没有要加载的文件 - 'gemname'(LoadError)

I suspect that may be there is some path remaining where to check out the gems repository.

我怀疑可能有一些路径留在哪里检查gems存储库。

I want to ask you if there is a way to do this.

我想问你是否有办法做到这一点。

Thanks a lot.

非常感谢。

Cheers, Juan.

干杯,胡安。

5 个解决方案

#1


18  

You could invoke you ruby script with

你可以调用ruby脚本

ruby -rubygems script.rb

or add rubygems to RUBYOPT

或者将rubygems添加到RUBYOPT

$ export RUBYOPT="rubygems"

#2


5  

put

require 'rubygems'

as first line of your ruby code and be safe. of course you can invoke with -rubygems switch (as Peter Krenn wrote) instead of it

作为您的红宝石代码的第一行并且是安全的。当然你可以用-rubygems开关调用(正如Peter Krenn写的那样)而不是它

#3


3  

In Unix you can:

在Unix中你可以:

$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby juans_masterpiece.rb

and in Windows:

在Windows中:

SET RUBYOPT=rubygems

or right-click on My Computer->Properties->Advanced->Environment Variables and then finally add the RUBYOPT variable there. Next time you open a cmd.exe run set and it will be there.

或右键单击我的电脑 - >属性 - >高级 - >环境变量,然后最后在那里添加RUBYOPT变量。下次打开cmd.exe运行集时,它将在那里。

#4


2  

You don't have to put it every time you require a gem — you just have to have it before the first time you require a gem. When you require Rubygems, it replaces the default require with a special one that does all the Rubygems magic.

每次需要宝石时都不需要它 - 你只需要在第一次需要宝石之前就拥有宝石。当你需要Rubygems时,它会用一个执行所有Rubygems魔术的特殊需求来替换默认需求。

But that's only in 1.8. You don't have to require Rubygems at all in Ruby 1.9 — so that's a very easy solution to the problem as long as you aren't dependent on 1.8-specific things.

但那只是1.8。在Ruby 1.9中,您根本不需要Rubygems - 只要您不依赖于1.8特定的东西,这就是解决问题的一个非常简单的方法。

#5


0  

Right-click the Computer Icon, then select Properties, then Additional system parameters, then Environment variables, there is a GUI for changing opts, click Create, put name and value, OK. This is an approximate translation of how you do this on windows 7, if you can't find the place try to google for "changing environment variables in {your windows version here}"

右键单击计算机图标,然后选择属性,然后选择其他系统参数,然后选择环境变量,有一个用于更改选项的GUI,单击创建,输入名称和值,确定。这是关于如何在Windows 7上执行此操作的近似翻译,如果您找不到该地方尝试谷歌“在{your windows version here}中更改环境变量”

#1


18  

You could invoke you ruby script with

你可以调用ruby脚本

ruby -rubygems script.rb

or add rubygems to RUBYOPT

或者将rubygems添加到RUBYOPT

$ export RUBYOPT="rubygems"

#2


5  

put

require 'rubygems'

as first line of your ruby code and be safe. of course you can invoke with -rubygems switch (as Peter Krenn wrote) instead of it

作为您的红宝石代码的第一行并且是安全的。当然你可以用-rubygems开关调用(正如Peter Krenn写的那样)而不是它

#3


3  

In Unix you can:

在Unix中你可以:

$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby juans_masterpiece.rb

and in Windows:

在Windows中:

SET RUBYOPT=rubygems

or right-click on My Computer->Properties->Advanced->Environment Variables and then finally add the RUBYOPT variable there. Next time you open a cmd.exe run set and it will be there.

或右键单击我的电脑 - >属性 - >高级 - >环境变量,然后最后在那里添加RUBYOPT变量。下次打开cmd.exe运行集时,它将在那里。

#4


2  

You don't have to put it every time you require a gem — you just have to have it before the first time you require a gem. When you require Rubygems, it replaces the default require with a special one that does all the Rubygems magic.

每次需要宝石时都不需要它 - 你只需要在第一次需要宝石之前就拥有宝石。当你需要Rubygems时,它会用一个执行所有Rubygems魔术的特殊需求来替换默认需求。

But that's only in 1.8. You don't have to require Rubygems at all in Ruby 1.9 — so that's a very easy solution to the problem as long as you aren't dependent on 1.8-specific things.

但那只是1.8。在Ruby 1.9中,您根本不需要Rubygems - 只要您不依赖于1.8特定的东西,这就是解决问题的一个非常简单的方法。

#5


0  

Right-click the Computer Icon, then select Properties, then Additional system parameters, then Environment variables, there is a GUI for changing opts, click Create, put name and value, OK. This is an approximate translation of how you do this on windows 7, if you can't find the place try to google for "changing environment variables in {your windows version here}"

右键单击计算机图标,然后选择属性,然后选择其他系统参数,然后选择环境变量,有一个用于更改选项的GUI,单击创建,输入名称和值,确定。这是关于如何在Windows 7上执行此操作的近似翻译,如果您找不到该地方尝试谷歌“在{your windows version here}中更改环境变量”