为什么 Perl 调试器找不到脚本找到的模块?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于 bourne 兼容:
这不是最好的解决方案。您实际上应该通过
cpan
安装它。如果它工作正常但无法安装,那么您可能需要强制
它。而且还有
On bourne-compatible:
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 toforce
it.And there is also
不要使用该位置 -
cpan
可能很快就会把它扔掉(正如 Eric 在他的评论中提到的,这只是一个构建目录,一段时间后就会被清除)。如果您可以在没有
use lib
行的情况下从脚本访问它,您可以通过以下方式找到其他(可能正确安装)版本,或者查看 @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 byor look at the @INC paths to see potential places it might be hiding
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'sforce install
suggestion could be worth a shot (and that should tell you where it is putting the files).