Example error:
Can't locate Statistics/Basic.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 .)
at /Share/home/zhangqf5/gongjing/Kethoxal_RNA_structure/scripts/icSHAPE-master/scripts/correlationRT.pl line 8.
Check whether the module has been installed as discussed here?
# display path to library if it's installed and found in PERL5LIB
$ perldoc -l Statistics::Basic
# /Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/lib/site_perl/5.22.1/Statistics/Basic.pod
So the installed module are not in @INC
path.
3 ways to around this error:
# push in @INC
BEGIN { unshift @INC, "some/path"; }
# addd lib
use lib "some/path";
# add .pm script (通常可用于指定自写的非依赖包)
require "/full/path/to/XXX.pm";
For example here below works for me:
#! /usr/bin/perl
use strict;
use warnings;
use File::Basename;
use Getopt::Std;
# add a lib to search path
use lib "/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1";
但是这个显性的指定lib
的方式有问题,虽然模块Statistics::Basic
可以正常的导入,但是其每个模块对应的函数无法正常使用。在这个脚本中,后面调用了Statistics::Basic
中的一个函数correlation
,因而报错。后面发现,在执行脚本时使用perl script.py
是可以的,原因在于调用的perl命令路径不一样。脚本默认的perl是/usr/bin/perl
,但是这个其实是有很多模块没有安装的,所以使用集群正常使用的perl可以正常运行。
查看默认的perl路径及其模块搜索路径:
$ which perl
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/bin/perl
$ perl -e 'print join "\n", @INC;'
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/lib/site_perl/5.22.1/x86_64-linux-thread-multi
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/lib/site_perl/5.22.1
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/lib/5.22.1/x86_64-linux-thread-multi
/Share/home/zhangqf/usr/perl-df/perls/perl-5.22.1/lib/5.22.1