Perl throws "Can't locate Config/YAML.pm in #INC" - perl

I'm getting Can't locate Config/YAML.pm in #INC (you may need to install the Config::YAML module) while running a perl script.
Can't locate Config/YAML.pm in #INC (you may need to install the
Config::YAML module) (#INC contains: /etc/perl
/usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18
/usr/local/lib/site_perl .) at myperlscript line 8. BEGIN
failed--compilation aborted at myperlscript line 8.
Line 8 of the script shows use Config::YAML;.
I'm using Ubuntu and have installed the libdata-yaml-perl and libyaml-perl packages, but still am getting the same error. What else is needed?

Config::YAML requires a different package. Install the libconfig-yaml-perl package and the problem will be fixed.

As the error says, something is missing in #INC. If you do have the module installed (perldoc -l YAML::Tiny for example) it might be installed in a location that is not added to #INC (see How is Perl's #INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?) for how it's constructed).
That means that there could be something wrong with environment variables: if for example PERL5LIB is not set (or not set correctly), it could also cause this error.
For example, if Perl is installed in /home/myusername/perl5, setting PERL5LIB="/home/myusername/perl5/lib/perl5" can fix this (e.g. in your ~/.profile, don't forget to log out and in).
For reference, here is what my Perl installation had autogenerated:
PATH="/home/myusername/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/home/myusername/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/myusername/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/myusername/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/myusername/perl5"; export PERL_MM_OPT;

Related

Can't locate XML/LibXML.pm in #INC

I am trying to run script which uses XML/LibXML package.
But, XML/LibXML package is already installed. I ran following command:
perl -MXML::LibXML -e 1. it did not give any output, that means this package is installed.
when i ran my script. Following error occured.
Can't locate XML/LibXML.pm in #INC (#INC contains:
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8
.). BEGIN failed--compilation aborted.
One more point to note is there is no directory "5.8.8" under /usr/lib64/perl5/site_perl/
Please suggest to overcome this issue.
There are three possibilities:
You have two installs of perl and you script is using the "wrong" one.
Either install XML::LibXML using the perl used by the script, or replace the script's shebang (#!) line with the output of the following:
perl -MXML::LibXML -le'print "#!".$^X'
Differences in the environment.
If XML::LibXML was installed in a nonstandard directory, it could be that PERL5LIB was used to communicate this to perl when you executed your test, but not when you run the script.
A permission issue.
This isn't very likely.
If the script is run as the same user as your test, it's not a permission issue.
If it is a permission issue, make sure the library directory is accessible to the user executing the script.

Cannot use already installed Perl Module on cPanel

I have already successfully installed the Perl module Crypt::CBC on cPanel.
But when adding the line "use Crypt::CBC;" I am getting the error:
Can't locate Crypt/CBC.pm in #INC (#INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at sagepay.pl line 128.
BEGIN failed--compilation aborted at sagepay.pl line 128.
Did I miss something? Quite new to Perl modules installation.
check the value of #INC by running this using your web server:
perl -e 'print "Content-type: text/plain\r\n\r\n" . join(":",#INC);'
#INC is where perl looks for modules. Perhaps they got installed in the wrong location.
You can add new locations with perl's -I option (see "man perlrun" for details)
I suspect that you may have added the module to cPanel instead of to the system Perl, for which you need to use WHM. Take a look at these instructions and follow the directions headed Install modules to the system Perl binary
Thanks everyone! Just a wrong path, I used this and it now works:
use lib '/data01/c1501978/perl/usr/lib/perl5';

Can't locate *** in #INC

I install perl modules in ~/.local/perl5. Here's part of ~/.bashrc:
export PERL_LOCAL_LIB_ROOT="$HOME/.local/perl5";
export PERL_MB_OPT="--install_base $HOME/.local/perl5";
export PERL_MM_OPT="INSTALL_BASE=$HOME/.local/perl5";
export PERL5LIB="$HOME/.local/perl5/lib/perl5:$PERL5LIB";
export PATH="$HOME/.local/perl5/bin:$PATH";
I've installed CSS::Inliner with
$ cpan
cpan[1]> install CSS::Inliner
and I have Inliner.pm at:
~/.local/perl5/lib/perl5/CSS/Inliner.pm
But when I use it -- perl can't find it:
perl -e 'use Inliner'
gives:
Can't locate Inliner.pm in #INC (#INC contains:
/home/boris/.local/perl5/lib/perl5/x86_64-linux-gnu-thread-multi
/home/boris/.local/perl5/lib/perl5 /etc/perl
/usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14
/usr/local/lib/site_perl .) at -e line 1. BEGIN failed--compilation
aborted at -e line 1.
why can't perl find the module?
Edit:
I'm trying to reproduce minimal working example given in documentation to CSS-Inliner:
use Inliner;
my $inliner = new Inliner();
$inliner->read_file({filename => 'myfile.html'});
print $inliner->inlinify();
If I use Inliner -- perl can't find it. If I
#!/usr/bin/perl
use CSS::Inliner;
my $inliner = new Inliner();
$inliner->read_file({filename => 'test.html'});
print $inliner->inlinify();
perl says
Can't locate object method "new" via package "Inliner"
(perhaps you forgot to load "Inliner"?) at ./1.perl line 5.
Edit 2:
Here's a minimal working example of CSS-Inliner:
#!/usr/bin/perl
use CSS::Inliner;
my $inliner = CSS::Inliner->new;
$inliner->read_file({filename => 'test.html'});
print $inliner->inlinify();
You should use the full module name in use and full class name when calling class methods:
use CSS::Inliner;
my $inliner = CSS::Inliner->new;
This could happen when you are not careful in installing modules. Once I simply copied the foo.pm into the official /usr/lib/perl5/site_perl directory. The foo.pm could be modules developed locally or third party. I did not pay attention to the umask. Files installed there are not readable by the world. When I use the module I will get the message saying: Cannot locate foo.pm in #INC(#INC contains /usr/lib/perl5/site_perl ....). Gee it is clearly there! Took me a while to check the file permission. Hope this may save some time for others who install their own modules. In make file you should use install -m 644 to make sure the installed module has read permission for others.

Whats does the Perl error "Can't locate Net/SSH/Perl.pm" mean?

I am running a perl script that uses SSH, but it prints the following error:
Can't locate Net/SSH/Perl.pm in #INC (#INC contains: /etc/perl
/usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10
/usr/local/lib/site_perl .) at newone.pl line 3. BEGIN
failed--compilation aborted at newone.pl line 3.
Perl can't seem to locate Net/SSH/Perl.pm. Why can't it find it and how do I install it?
Your code is fine, although I haven't checked it as the error is due to a missing perl module.
What's the easiest way to install a missing Perl module?
You need to install and/or include the appropriate SSH library for perl. You can install it using this command:
cpan install Net::SSH::Perl

Can't locate File/Glob.pm in #INC (#INC contains: D:/tools/lib .) at directory.pl line 2

I get this error when running my perl code
Can't locate File/Glob.pm in #INC (#INC contains: D:/tools/lib .) at directory.pl line 2.
line 2: #files=<*>;
When i run the command, I get,
Y:\perl\perl>perldoc -l File::Glob
D:\tools\lib\perl\510\File\Glob.pm
So I think the File::Glob module is installed?
#INC should be set correctly upon installation of Perl. When it doesn't match your configuration, you seem to have messed up something.
However, if the current value of #INC doesn't fit your needs, you have various options:
Add D:\tools\lib\perl\510\ to the
environment variable PERL5LIB (or PERLLIB if this doesn't work)
Specify #INC on startup:
perl -I D:\tools\lib\perl\510\
Instead of writing use libname, you can write use path/to/libname
Using a BEGIN block before the use statements:
BEGIN {
push #INC,"D:\tools\lib\perl\510\";
}
See also http://perldoc.perl.org/perlvar.html for a short introduction.