Cannot use already installed Perl Module on cPanel - perl

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';

Related

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

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;

Can I move perl modules without breaking the system?

I have the exact problem described here:
Perl can't find module when run from cron.daily except that my problem applies to a perl script running from crontab.
In my case the error message is:
May 24 22:12:02 trackcam3 test_cron: Can't locate Image/Grab.pm in #INC (you may need to install the Image::Grab module) (#INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /home/darren/upload_image.pl line 33, <DATA> line 1.
May 24 22:12:02 trackcam3 test_cron: BEGIN failed--compilation aborted at /home/darren/upload_image.pl line 33, <DATA> line 1.
The solutions at the link all add something to the path. I would like to know if I can move or copy the modules to somewhere they can be found when perl scripts from crontab.
As part of troubleshooting I have already loaded cron with the same PATH as I have from the terminal but that is not enough to allow the perl module to be found.
The missing module is in ~/perl5/lib/perl5 which is not in #INC
The same perl script call modules that are located at
/usr/lib/arm-linux-gnueabihf/perl5/5.24/Image/Magick
Should it be somewhere else? At present /usr/lib/perl5 is empty. The OP in the link asked the same question in the link but didn't receive an answer.
Try:
use lib glob( '~/perl5/lib/perl5' );
use Image::Grab;
The use lib must come before many use module.
Follow the link in the following comment by #haukex to arrive at a full explanation.

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.

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

I have a .pl script in which starts by:
#!/usr/bin/perl
use XML::XPath;
use Getopt::Long;
I can't seem to run that via perl myScript.pl, having this error:
(#INC contains: /usr/share/ /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 most_generic_wrapper.pl line 3.
BEGIN failed--compilation aborted at myScript.pl line 3.
1- I tried to locate the XPath.pm file and export that as:
export PERL5LIB=/usr/share/perl5/XML/Twig
and
export PERL5LIB=/usr/share/perl5/XML
2- Installed perl -MCPAN -e 'install XML::Parser'
3- Used -I to explicitly define the path as:
perl -I perl -MCPAN -e 'install XML::Parser' myScript.pl
4- changing the line 3 to use XML::Twig::XPath; led to:
cannot use XML::Twig::XPath: neither XML::XPathEngine 0.09+ nor XML::XPath are available at /usr/share/perl5/XML/Twig/XPath.pm line 11.
BEGIN failed--compilation aborted at /usr/share/perl5/XML/Twig/XPath.pm line 13.`
But none of them solved the issue and I keep receiving the same error at line.3.
P.S: Running on CentOS 6.2 with the kernel 2.6.32-358 and perl --version=v5.10.1 (*) built for x86_64-linux-thread-multi
Any helps would be appreciated,
Your title says XML::XPath can't be found, but your question indicates you tried to install XML::Parser. Did you try to install XML::XPath?
From man perlrun: "If PERL5LIB is not defined, PERLLIB". You seem to have tried setting PERLIB5 (notice the spelling difference: the var is PERL5LIB (or PERLLIB), not PERLIB5).
From man perlrun: "PERL5LIB -- A list of directories in which to look for Perl library files before looking in the standard library and the current directory." You seem to have tried setting it to the full path to a .pm file, rather than a directory.
The file you assigned would be XML::Twig::XPath, not XML::XPath; those are two different Perl modules.
Edit: After looking at your revised question:
I'm not sure if your script requires XML::Twig::XPath or XML::XPath, or if either one can provide the API you need. However, XML::Twig::XPath seems to depend on XML::XPath so you will need XML::XPath no matter what, and it looks like XML::XPath is not installed on your system. I think that's probably the main problem. Please try to install XML::XPath using CPAN.
The value of the PERL5LIB variable (or the argument to the -I option) should be the directory that sits at the base of the package-qualified module file. For example, if XML::XPath is located at ~/perl_custom_modules/XML/XPath.pm, then you need to set PERL5LIB (or the -I argument) to ~/perl_custom_modules. The XML directory is part of the package qualification of the module, so does not need to be included in the include path.

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.