Linux perl 库路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12320543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
perl library path
提问by Elb
I need to retrieve the path where the perl libraries Statistics and Distributions are located. The path is necessary to run the script. I'm on a computer cluster. Can anyone help me?
我需要检索 perl 库统计和分布所在的路径。该路径是运行脚本所必需的。我在一个计算机集群上。谁能帮我?
Thanks
谢谢
采纳答案by Ben Deutsch
This answer assumes that the module is in fact installed, but not in a place that perl
is looking for.
此答案假定该模块实际上已安装,但未安装在perl
正在查找的位置。
Generally, the Perl module Statistics::Distributions
will be contained in a file called Statistics/Distributions.pm
. On Linux and similar systems, one can search for these files quickly with the locate
command:
通常,Perl 模块Statistics::Distributions
将包含在名为Statistics/Distributions.pm
. 在 Linux 和类似系统上,可以使用以下locate
命令快速搜索这些文件:
locate Statistics/Distributions.pm
If it is installed, locate
will spit out a line similar to
如果安装了,locate
会吐出类似的一行
/opt/my_perl/lib/Statistics/Distributions.pm
You can then instruct the perl
interpreter to look in this path, too, in various ways. One is to define the environment variable PERL5LIB
, i.e. from bash
:
然后,您也可以指示perl
解释器以各种方式查看此路径。一种是定义环境变量PERL5LIB
,即来自bash
:
prompt> PERL5LIB=/opt/my_perl/lib/ ./myscript.pl
Or you can use the perl -I
switch:
或者您可以使用perl -I
开关:
prompt> perl -I/opt/my_perl/lib/ ./myscript.pl
Or you can modify the script to use lib
; there is more than one way to do it ;-)
或者您可以将脚本修改为use lib
; 有不止一种方法可以做到;-)
回答by zigdon
If you mean you need the path of a module you're using in a program, that's stored in %INC
:
如果你的意思是你需要你在程序中使用的模块的路径,它存储在%INC
:
$ perl -MLWP::Simple -le 'print $INC{"LWP/Simple.pm"}'
/usr/share/perl5/LWP/Simple.pm
回答by ikegami
"Can't locate XXX in @INC
" usually indicates the module isn't installed. Have you installed Statistics::Distributions?
“ Can't locate XXX in @INC
”通常表示未安装模块。您是否安装了Statistics::Distributions?
cpan Statistics::Distributions
回答by Sergey Sinkovskiy
perldoc -m Your::Module
- displays source of module
perldoc -m Your::Module
- 显示模块的来源
perldoc -l Your::Module
- display path to library if it's installed and found in PERL5LIB, -I, @INC, etc.
perldoc -l Your::Module
- 如果已安装并在 PERL5LIB、-I、@INC 等中找到,则显示库的路径。
回答by leonardo
I had the same trouble and it can be fixed both ways:
我遇到了同样的问题,可以通过两种方式解决:
1) by running the comand perl -I/blabla/folder_your_module_is_installed/blib/lib/ ./script.pl
1) 通过运行命令 perl -I/blabla/folder_your_module_is_installed/blib/lib/ ./script.pl
for dummies like me, it is important to note that the end of the path is "lib/", not "lib/Other_folder/". Because there are more folders after it.
对于像我这样的傻瓜,重要的是要注意路径的结尾是“lib/”,而不是“lib/Other_folder/”。因为后面有更多的文件夹。
2) inside the script you can write: use lib 'blabla/folder_your_module_is_installed/blib/lib/';
2)在脚本中你可以写:使用 lib 'blabla/folder_your_module_is_installed/blib/lib/';