Installed Module not contained in the Perl's @

2019-07-29 07:54发布

I have an issue on including the Excel-Writer-XLSX module in the @INC path. I did some research before posting this question and tried several solutions, but they all failed.

So I did

$sudo perl -MCPAN -e 'install Excel::Writer::XLSX'

But after I run the code, I got this message

--can't locate Excel/Writer/XLSX.pm in @INC(you may need to install the Excel::Writer::XLSX module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level/...)

This is not a duplicate question, because the Excel::Writer::XLSX module has been successfully installed in my computer and I don't need to install it again. The thing is when I checked my library folder, the perl5 folder is not there, as it was suggested by the @INC path. Instead, Perl5 folder is in my user folder...and actually the module can be found in the lib folder inside the perl5 folder

I'm not quite sure what is happening...Why the @INC path shows the perl/5.18 is inside the library folder? If you know how to solve this issue, please advice. Thank you so much!

标签: excel perl
2条回答
\"骚年 ilove
2楼-- · 2019-07-29 08:28

Make sure the @INC contains the path where your modules are getting installed. You can specify that by

export PERL5LIB=/home/foobar/code (For Linux) (Add this to ~/.bashrc to make it always available when you log-in.)

set PERL5LIB = c:\path\to\dir (For Windows)


Also see:

查看更多
迷人小祖宗
3楼-- · 2019-07-29 08:30

At the very top of your perl code right after #!/usr/bin/perl

BEGIN
{
push(@INC, '/home/penny/perlModules');
}
use my::module;
use File::Path;
...

This will allow your code to use any module you've installed in perlModules dir.

Downside is you have to modify code. Or you can use PERL5LIB env path as answered above.

查看更多
登录 后发表回答