为什么我的Perl程序会抱怨“无法在@INC中找到URI.pm"? [英] Why does my Perl program complain "Can't locate URI.pm in @INC"?
问题描述
我是Perl的新手.运行脚本时出现以下错误:
I'm new to Perl. I get the following error when I run a script:
Can't locate URI.pm in @INC (@INC contains: /usr/local/packages/perl_remote/5.6.1/lib/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/5.6.1 /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1 /usr/local/packages/perl_remote/5.6.1/lib/site_perl .) at (eval 2) line 3.
Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/HTTP/Request.pm line 3.
Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/UserAgent.pm line 10.
BEGIN failed--compilation aborted at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/UserAgent.pm line 10.
Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/Simple.pm line 26.
BEGIN failed--compilation aborted at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/Simple.pm line 26.
Compilation failed in require at txotf_0_install.pl line 35.
BEGIN failed--compilation aborted at txotf_0_install.pl line 35.
这可能是什么原因,以及如何使脚本正常工作.任何帮助将不胜感激.
What could be the possible reasons of this and how do I get the script to work. Any help will be appreciated.
推荐答案
-
可能您没有安装
URI
.它可能未保存在计算机上的任何位置,或者可能已安装"在某个位置.Possibly you do not have
URI
installed. It might not be saved anywhere on your machine, or it might be "installed" in a location.- 如果尚未安装,则需要从CPAN安装.
- 如果将其保存到计算机中,则只需让系统知道从何处获取它.
如果必须从CPAN安装它,则可能需要管理员权限才能将其放入列出的目录中.但是CPAN允许您将其安装到用户目录,因此您仍然可以安装它.
If you have to install it from CPAN, you likely need administrator privileges to put it in the listed directories. But CPAN will allow you to install it to a user directory, so you can still install it.
因此,如果您不能在
@INC
中列出的目录中安装该模块,则可以采用多种方法.So if you can't install the module in the directories listed in
@INC
, then there are the various ways.-
Perl 5读取一个名为
PERL5LIB
的环境变量.该数组"中的任何目录都将前缀到@INC
.因此,$ENV{PERL5LIB}
目录结构中的任何内容都将优先于任何系统目录. (请参见此处)
Perl 5 reads a environment variable called
PERL5LIB
. Any directory in that "array" will be prepended to@INC
. So anything in the directory structure of$ENV{PERL5LIB}
will be preferred to any system directory. (see here)
另一种实现方法是根据 script .
use lib
编译指示还将指定的目录插入到@INC
中. (请参见 lib )Another way you can do this is per script. The
use lib
pragma also inserts specified directories into@INC
. (see lib)use lib '/path/to/URI/module'; use URI;
-
最后一种方法是,您可以每次运行 进行操作.您可以在命令行
perl -I/path/to/URI/module -e 1
上使用-I
开关运行perl(请参见 perlrun ) The final way, you can do it per run. You can run perl with the
-I
switch on the command lineperl -I/path/to/URI/module -e 1
(see perlrun)这篇关于为什么我的Perl程序会抱怨“无法在@INC中找到URI.pm"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!