我用CPAN成功安装了一个模块,但是perl找不到它.为什么? [英] I installed a module successfully with CPAN, but perl can't find it. Why?

查看:735
本文介绍了我用CPAN成功安装了一个模块,但是perl找不到它.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了这样的CPAN模块:

 cpan Acme
 

根据输出,安装成功:

 Running install for module 'Acme'
...
All tests successful.
Files=2, Tests=3,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.04 cusr  0.00 csys =  0.06 CPU)
Result: PASS
  INGY/Acme-1.11111111111.tar.gz
  /usr/bin/make test -- OK
Running make install
Manifying 1 pod document
Installing /home/foo/perl5/lib/perl5/Acme.pod
Installing /home/foo/perl5/lib/perl5/Acme.pm
Installing /home/foo/perl5/man/man3/Acme.3pm
Appending installation info to /home/foo/perl5/lib/perl5/x86_64-linux-thread-multi/perllocal.pod
  INGY/Acme-1.11111111111.tar.gz
  /usr/bin/make install  -- OK
 

但是当我尝试使用该模块时,出现错误:

 $ perl -MAcme -e1
Can't locate Acme.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
 

为什么即使成功安装了模块也无法找到Perl?我该如何解决?

解决方案

模块已安装在此处:

 /home/foo/perl5/lib/perl5/Acme.pm
 

但是perl在 @INC 中查找模块. :

 /usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
.
 

(.是指当前工作目录.)

由于该模块不在@INC中,因此perl在没有帮助的情况下无法找到它.

为什么CPAN在@INC之外安装模块?

一个常见的原因是将CPAN配置为引导 local :: lib ,以便安装模块在您的主目录中,而不是在系统Perl目录中.如果您具有 CPAN 1.9463或更高版本,并且您在默认安装路径,第一次运行CPAN时将提示:

 Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib]
 

如果您选择引导local :: lib(默认值),则该模块将安装在~/perl5内部.您可能还会收到类似以下提示:

 Would you like me to append that to /home/foo/.bashrc now? [yes]
 

如果选择是"(默认设置),则会将一些变量添加到.bashrc(或外壳程序的等效项)中,以便将来运行CPAN时,模块将继续安装在主目录中:

 PATH="/home/foo/perl5/bin${PATH+:}${PATH}"; export PATH;
PERL5LIB="/home/foo/perl5/lib/perl5${PERL5LIB+:}${PERL5LIB}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/foo/perl5${PERL_LOCAL_LIB_ROOT+:}${PERL_LOCAL_LIB_ROOT}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/foo/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/foo/perl5"; export PERL_MM_OPT;
 

我该如何解决?

如果CPAN将上述环境变量添加到您的.bashrc(或等效项)中,最简单的操作是启动一个新的shell(或获取您的.bashrc的源代码).这将设置 PERL5LIB ,以便perl可以找到安装在~/perl5中的模块. /p>

另一方面,如果您具有sudo访问权限,并且希望CPAN将模块安装在系统Perl目录中而不是您的主目录中,请从您的.bashrc(或等效文件)中删除环境变量设置,然后启动CPAN shell,然后运行:

o conf init

这将重置CPAN配置.如果您要引导local :: lib ;,则会再次提示您.输入"sudo".一般来说,我不建议您这样做;通常最好使用发行版的软件包管理器(例如yum,apt)在系统Perl目录中安装模块.

另请参阅:如何在不在@INC的目录中使用" Perl模块?

I installed a CPAN module like this:

cpan Acme

According to the output, the installation was successful:

Running install for module 'Acme'
...
All tests successful.
Files=2, Tests=3,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.04 cusr  0.00 csys =  0.06 CPU)
Result: PASS
  INGY/Acme-1.11111111111.tar.gz
  /usr/bin/make test -- OK
Running make install
Manifying 1 pod document
Installing /home/foo/perl5/lib/perl5/Acme.pod
Installing /home/foo/perl5/lib/perl5/Acme.pm
Installing /home/foo/perl5/man/man3/Acme.3pm
Appending installation info to /home/foo/perl5/lib/perl5/x86_64-linux-thread-multi/perllocal.pod
  INGY/Acme-1.11111111111.tar.gz
  /usr/bin/make install  -- OK

But when I try to use the module, I get an error:

$ perl -MAcme -e1
Can't locate Acme.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

Why can't perl find the module even though it was installed successfully? How can I fix this?

解决方案

The module was installed here:

/home/foo/perl5/lib/perl5/Acme.pm

But perl looks for modules in @INC, which in this case contains:

/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
.

(. refers to the current working directory.)

Since the module is not in @INC, perl can't find it without some help.

Why did CPAN install the module outside of @INC?

A common cause is configuring CPAN to bootstrap local::lib so that modules are installed in your home directory instead of in the system Perl directories. If you have CPAN 1.9463 or higher and you don't have write permissions in the default install path, the first time you run CPAN you will be prompted:

Warning: You do not have write permission for Perl library directories.

To install modules, you need to configure a local Perl library directory or
escalate your privileges.  CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available).  You may also
resolve this problem manually if you need to customize your setup.

What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
 [local::lib]

If you choose to bootstrap local::lib (the default), the module will be installed inside ~/perl5. You may also be prompted something like:

Would you like me to append that to /home/foo/.bashrc now? [yes]

If you choose yes (the default), some variables will be added to your .bashrc (or the equivalent for your shell) so that when you run CPAN in the future, modules will continue to be installed in your home directory:

PATH="/home/foo/perl5/bin${PATH+:}${PATH}"; export PATH;
PERL5LIB="/home/foo/perl5/lib/perl5${PERL5LIB+:}${PERL5LIB}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/foo/perl5${PERL_LOCAL_LIB_ROOT+:}${PERL_LOCAL_LIB_ROOT}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/foo/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/foo/perl5"; export PERL_MM_OPT;

How can I fix it?

If CPAN added the above environment variables to your .bashrc (or equivalent), the simplest thing to do is start a new shell (or source your .bashrc). This will set PERL5LIB so that perl can find modules installed in ~/perl5.

On the other hand, if you have sudo access and you want CPAN to install modules in the system Perl directories instead of in your home directory, delete the environment variable settings from your .bashrc (or equivalent), start the CPAN shell, and run:

o conf init

This will reset the CPAN configuration. You will be prompted again if you want to bootstrap local::lib; enter "sudo" instead. In general, I wouldn't recommend doing this; it's usually better to use your distro's package manager (e.g. yum, apt) to install modules in the system Perl directories.

Also see: How do I 'use' a Perl module in a directory not in @INC?

这篇关于我用CPAN成功安装了一个模块,但是perl找不到它.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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