不断收到错误消息“无法在@INC中找到Image/Grab.pm";在安装Perl mod之后 [英] Keep getting error "Can't locate Image/Grab.pm in @INC" after installing the Perl mod

查看:217
本文介绍了不断收到错误消息“无法在@INC中找到Image/Grab.pm";在安装Perl mod之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程有点陌生,在编写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中运行脚本时遇到的错误:

在@INC中找不到Image/Grab.pm(@INC包含: /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.) getimage.pl第7行.BEGIN失败-在getimage.pl处中止编译 第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

I'm a bit new to programming and I'm having some trouble writing a Perl script that will grab all the images from a webpage and save them in a specified directory.

Here's my code:

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;

This is the error I get when I run the script in 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.

Thanks for the help

解决方案

That's a standard error when you haven't installed the module. Image::Grab does not come with perl. There are lots of perl modules available on something called cpan, for instance:

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

Modules are libraries of functions that someone has written in perl and made available for your use.

Now, you have to figure out how to install modules. See if this works:

$ 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().

then

cpan> install Image::Grab.  

The first time you do that, you'll have to answer a lot of questions.

Once you are done:

cpan> q  ('q' is for quit)

Response to comment:

1) Try updating your CPAN module:

cpan> install CPAN
cpan> reload cpan

then:

cpan> install Image::Grab

Installing from source is fine, but if you can get cpan to work, then it takes care of downloading all the dependencies, so it is hassle free. I just used cpan to download Image::Grab, and I got no errors. It has no dependencies that need to be downloaded.

2) What is the output of:

$ perl --version (it looks like you are using perl 5.10.1)  

Also, at the bottom of your question add the entire output from your cpan attempt.

3) Try installing another module, like:

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

这篇关于不断收到错误消息“无法在@INC中找到Image/Grab.pm";在安装Perl mod之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆