perl - 安装 Perl mod 后,不断收到错误 "Can' t locate Image/Grab.pm in @INC”

标签 perl syntax-error runtime-error perl-module

我对编程有点陌生,我在编写一个 Perl 脚本时遇到了一些麻烦,该脚本将从网页中获取所有图像并将它们保存在指定的目录中。

这是我的代码:

use warnings;
use strict;
use lib '/home/User1/strawberry/cpan/build';
use Image::Grab;

$pic = Image::Grab->new(SEARCH_URL=>'http://www.examplesite.com',
                          REGEXP    =>'.*\.gif|.*\.jpg');
my $dir = 'images';

opendir (IMG, ">>$dir") || die "Directory doesn't exist - $!\n";
foreach ($pic) {
        print IMG "$_\n";
}
closedir IMG;

这是我在 PuTTY 中运行脚本时遇到的错误:

Can't locate Image/Grab.pm in @INC (@INC contains: /home/User1/strawberry/cpan/build /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at getimage.pl line 7. BEGIN failed--compilation aborted at getimage.pl line 7.



谢谢您的帮助

最佳答案

当您尚未安装模块时,这是一个标准错误。 Image::Grab 不附带 perl。在名为 cpan 的东西上有很多可用的 perl 模块,例如:

http://search.cpan.org/~mahex/Image-Grab-1.4.2/lib/Image/Grab.pod .

模块是有人用 perl 编写并可供您使用的函数库。

现在,您必须弄清楚如何安装模块。看看这是否有效:

$ perl -MCPAN -e shell

-M => Use the module specified, in this case CPAN(comes with perl)  
-e => execute the following perl code, in this case the function shell().

然后
cpan> install Image::Grab.  

第一次这样做时,你必须回答很多问题。

完成后:
cpan> q  ('q' is for quit)

回复评论:

1) 尝试更新您的 CPAN 模块:
cpan> install CPAN
cpan> reload cpan

然后:
cpan> install Image::Grab

从源代码安装很好,但如果你可以让 cpan 工作,那么它会负责下载所有依赖项,所以它很容易。我刚刚使用 cpan 下载 Image::Grab,我没有收到任何错误。它没有需要下载的依赖项。

2)什么是输出:
$ perl --version (it looks like you are using perl 5.10.1)  

此外,在您问题的底部添加您的 cpan 尝试的整个输出。

3)尝试安装另一个模块,如:

http://search.cpan.org/~rehsack/List-MoreUtils-0.402/lib/List/MoreUtils.pm

关于perl - 安装 Perl mod 后,不断收到错误 "Can' t locate Image/Grab.pm in @INC”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28059956/

相关文章:

javascript - node.js ParseError - 哪个文件抛出错误?

perl - 我如何在 Perl 中使用套接字?有模块吗?

linux - 从 Net::LDAP Perl 连接到 Active Directory

excel - Perl(或Python)和Excel有没有办法确定单元格中多行文本使用的字体类型?

xml - 尝试使用 XML::LibXML 模块拆分 XML 文件时出错

javascript - jQuery:在 split() 或 text() 之后出现语法错误?

python - 无效的语法错误python 2.6

jquery - <div> onclick未被捕获的SyntaxError?

python - 运行时错误: The classifier does not expose "coef_" or "feature_importances_" attributes

Scala 在给数字赋值时不会给出编译时错误?