为什么 Perl 调试器找不到脚本找到的模块?

发布于 2024-10-08 00:13:36 字数 1160 浏览 8 评论 0原文

使用 CPAN,我安装了 GD::Graph 来制作水平堆叠条形图。 CPAN 将模块安装在 /root/.cpan/build/GD-2.45-4PSn9K 中,该模块不在 @INC 中。在我的脚本中,我可以通过添加来访问模块。

use lib "/root/.cpan/build/GD-2.45-4PSn9K"

脚本现在可以毫无问题地生成图表。我想使用 perl 调试器(“perl -d myscript.pl”),但它抱怨无法找到 GD.pm(位于该路径中)。我添加了 PERL5LIB 的路径,并使用“perl -V”进行了验证,但调试器仍然找不到它。

也许解决这个问题的一种方法是将 GD 安装在 @INC 路径之一中,但是 a) 我不知道该怎么做,b) 我真的很想了解发生了什么。

这是在 Fedora Core 12 上。

我不知道是否有什么区别,但 GD::Graph 实际上在我的主脚本包含的模块中使用。主脚本不使用它。

更新:按照下面的建议,我重新进入 CPAN 并强制安装。 CPAN 表示它在 /root/.cpan/(等)处找到了安装,并将该路径添加到 @INC。然后我手动从.cpan目录中删除GD并再次安装。这次 CPAN 将其放在同一个位置,并且也在 /usr/local/lib/perl5/GD-2.45PSn9K" 中。它在@INC 的两个路径前面添加了路径。我已经验证了它的存在,并且 perl 调试器声称正在查找那里,但仍然找不到 GD.pm(在那里)并且不会运行该脚本

@INC:
 /usr/local/lib/perl5/GD-2.45-4PSn9K/
  (and others)

来自 perl -d:

Can't locate loadable object for module GD in @INC (@INC contains:   

... 并列出该路径 。它确实存在:

[root /]# find . -name "GD.pm"
./usr/local/lib/perl5/GD-2.45-4PSn9K/GD.pm
./usr/local/lib/perl5/GD-2.45-4PSn9K/blib/lib/GD.pm
 (and the /root/.cpan paths)

Using CPAN, I've installed GD::Graph to make horizontal stacked bar charts. CPAN installed the modules in /root/.cpan/build/GD-2.45-4PSn9K, which is not in @INC. In my script, I'm able to access the modules by adding

use lib "/root/.cpan/build/GD-2.45-4PSn9K"

The script now generates the charts with no problems. I wanted to use the perl debugger ("perl -d myscript.pl") but it complains about not being able to find GD.pm (which is in that path). I added the path to PERL5LIB, verified with "perl -V", but still the debugger can't find it.

Perhaps one way around this is to have GD installed in one of the @INC paths, but a) I don't know how to do that, and b) I really would like to understand what's going on.

This is on Fedora Core 12.

I don't know if if makes a difference, but GD::Graph is actually used in a module which is included by my main script. The main script does not use it.

Update: Following suggestions below, I re-entered CPAN and forced the installation. CPAN said it found the installation at /root/.cpan/ (etc) and pre-pended that path to @INC. I then manually deleted GD from the .cpan directory and went to install again. This time CPAN put it in the same place, and also in /usr/local/lib/perl5/GD-2.45PSn9K". It prepended both paths to @INC. I've verified that it's there, and the perl debugger claims to be looking there, but still cannot find GD.pm (which is there) and won't run the script.

@INC:
 /usr/local/lib/perl5/GD-2.45-4PSn9K/
  (and others)

From perl -d:

Can't locate loadable object for module GD in @INC (@INC contains:   

... and lists that path among its others. It really is there:

[root /]# find . -name "GD.pm"
./usr/local/lib/perl5/GD-2.45-4PSn9K/GD.pm
./usr/local/lib/perl5/GD-2.45-4PSn9K/blib/lib/GD.pm
 (and the /root/.cpan paths)

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

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

发布评论

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

评论(2

浪荡不羁 2024-10-15 00:13:36

关于 bourne 兼容:

export PERL5LIB=$PERL5LIB:/root/.cpan/build/GD-2.45-4PSn9K

这不是最好的解决方案。您实际上应该通过 cpan 安装它。如果它工作正常但无法安装,那么您可能需要强制它。

force install GD::Graph

而且还有

perl -I/root/.cpan/build/GD-2.45-4PSn9K -d myscript.pl

On bourne-compatible:

export PERL5LIB=$PERL5LIB:/root/.cpan/build/GD-2.45-4PSn9K

This isn't the best solution. You should actually install this via cpan. If it's working fine and won't install, then you might need to force it.

force install GD::Graph

And there is also

perl -I/root/.cpan/build/GD-2.45-4PSn9K -d myscript.pl
街道布景 2024-10-15 00:13:36

不要使用该位置 - cpan 可能很快就会把它扔掉(正如 Eric 在他的评论中提到的,这只是一个构建目录,一段时间后就会被清除)。

如果您可以在没有 use lib 行的情况下从脚本访问它,您可以通过以下方式找到其他(可能正确安装)版本,

use GD;
warn $INC{"GD.pm"};

或者查看 @INC 路径以查看它可能隐藏

warn join, "\n", @INC;

史努比的 perldoc lm 技巧也很好,但如果您在脚本中使用 @INC 进行其他操作,则可能不完全准确。

如果您确实需要 use lib 行让它在脚本版本中工作,那么可能它没有正确安装,因此 Axeman 的 force install 建议值得一试(这应该告诉你它把文件放在哪里)。

Don't use that location - cpan will probably throw it away soon (as Eric mentioned in his comment, that's just a build directory, and these get cleaned away after a while).

If you can access it from your script without that use lib line you can find the other (presumably properly installed) version by

use GD;
warn $INC{"GD.pm"};

or look at the @INC paths to see potential places it might be hiding

warn join, "\n", @INC;

Snoopy's perldoc lm trick is good too, but might not be completely accurate if you have other things playing with @INC in the script.

If you do need that use lib line to get it to work in the script version, then presumably it wasn't installed properly so Axeman's force install suggestion could be worth a shot (and that should tell you where it is putting the files).

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