Perl Compilation Error: "Can't locate local/lib.pm" - perl

As a Perl rookie, I have made a rookie mistake.
I was working on a project that required an HTML parser so I thought I'd install Perl's HTML::TreeBuilder::XPath module, so I dove into cpan and perlbrew without a full understanding of how they work. I created a local library, but would like to return everything back to default. However, I get this error every time I open a terminal window (twice, for some reason):
Can't locate local/lib.pm in #INC (#INC contains:
/Users/James/perl5/lib/perl5
/Library/Perl/5.12/darwin-thread-multi-2level
/Library/Perl/5.12
/Network/Library/Perl/5.12/darwin-thread-multi-2level
/Network/Library/Perl/5.12
/Library/Perl/Updates/5.12.4/darwin-thread-multi-2level
/Library/Perl/Updates/5.12.4
/System/Library/Perl/5.12/darwin-thread-multi-2level
/System/Library/Perl/5.12
/System/Library/Perl/Extras/5.12/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.12 .).
BEGIN failed--compilation aborted.
I've seen the similar StackOverflow question here but I do not have apt-get installed.
How can I reset my machine so that this error no longer appears and it uses the default library?

The local::lib installation instructions tell you to add a line to your .bashrc or .bash_profile. From your error, it looks like the line
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
is still present. Look for it and remove it.

For me this meant I had an earlier aborted run of cpan's installation.
fix: remove ~/.cpan and ~/perl5 dirs, and remove anything about them from .bashrc, and do it again...

Related

Openshift Perl dependencies not loading from .openshift/cpan.txt

I have reviewed the dependency documentation found here:
https://help.openshift.com/hc/en-us/articles/202185484-Adding-dependencies-to-applications
And reviewed the information on .openshift/cpan.txt replacing deplist.txt found here:
https://developers.openshift.com/en/perl-overview.html#_template_repository_layout
I have attempted to use the following file in both locations
File::Slurp
File::Path
File::Basename
DBI
XML::Simple
Moose
However the build does not seem to recognize these dependencies. The build does not report errors, but the cpan modules are not available.
[myapp-mydomain.rhcloud.com]\> perl -e "use File::Slurp"
Can't locate File/Slurp.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 -e line 1.
BEGIN failed--compilation aborted at -e line 1.
This is a php application with mySql and phpMyAdmin cartridges but I have not found any way to add a "Perl Cartridge" and I saw a post (can't find the link) that indicated it was not necessary as perl was available with all apps. I think I'm missing something somewhere, maybe a Perl cartridge or configuration file is necessary, or maybe headers other content needed in the cpan.txt file? The documentation indicates that the cpan.txt file should "look something like this" - but I could not find anything that gave a real file format spec.
Thanks in advance for your help.
Since you are using the PHP cartridge, you will not be able to automatically install Perl modules using the above methods. That only works on the Perl cartridge. You can try sshing into your gear and running the "perl -MCPAN -e shell" manually, but you might not have write access to the ~/.cpan directory on your gear, so that may not work either. If you can provide more information about what you are trying to do someone might have a suggested solution.

Installing cURL modules for Perl on Windows

I have ActivePerl 5.14.2 on my Windows machine. I have been trying to install the LWP cURL module. I have already installed the libcurl-dev library and GCC on my machine.
I also understand that LWP cURL has a dependency on the WWW-Curl-Easy module. So I installed that too. I installed all these through the command lines using the steps given in the Readme files. I ran the perl makefile.pl command followed by a make and a make install. No errors were given out during the installation.
I am trying to execute this sample code to test my LWP cURL installation:
use LWP::Curl;
use strict;
use warnings;
my $lwpcurl = LWP::Curl->new();
my $content = $lwpcurl->get('http://search.cpan.org','http://www.cpan.org');
I am receiving the below error:
Can't locate loadable object for module WWW::Curl in #INC (#INC
contains: C:/Perl64/site/lib C:/Perl64/lib .) at
C:/Perl64/site/lib/WWW/Curl.pm line 11. BEGIN failed--compilation
aborted at C:/Perl64/site/lib/WWW/Curl.pm line 11. Compilation failed
in require at C:/Perl64/site/lib/WWW/Curl/Easy.pm line 9. Compilation
failed in require at C:/Perl64/site/lib/LWP/Curl.pm line 5. BEGIN
failed--compilation aborted at C:/Perl64/site/lib/LWP/Curl.pm line 5.
Compilation failed in require at D:\Varsha\Curl.pl line 1. BEGIN
failed--compilation aborted at D:\Varsha\Curl.pl line 1.
Where am I going wrong?
This is probably not the direction you want to go, but I'd advise you to consider upgrading your perl and changing distributions:
Install Strawberry Perl - 5.18.2.2 is the currently recommended version.
Install cpanm: perl -MCPAN -e "install App::cpanminus"
Install LWP::Curl: cpanm LWP::Curl
I won't bother trying convince you of the change, but Strawberry Perl and cpanm in combination make installing modules a lot easier than having to dealing with the proprietary ppm's of ActivePerl in my opinion.
Just something to consider if you ever get tired of the occasional headaches.
The error means that WWW::Curl is either not installed or its path is not searchable (it's not in #INC). So the solutions are
Make sure that the module is installed.
Add the path where the module is installed to the #INC. Since you are on Windows, you can use set PERL5LIB = c:\path\to\dir
For a permanent solution follow the below:
Right-click My Computer and click Properties.
In the System Properties window, click on the Advanced tab.
In the Advanced section, click the Environment Variables button.
In the Environment Variables window in the "User variables for Foo Bar" section click on New and type in the following:
Variable name: PERL5LIB
Variable value: c:\path\to\dir
Then click OK 3 times. Windows that you open after this will already know about the new variable. Type this in the command window, to see the newly set value:
echo %PERL5LIB%
This will add the private /home/foobar/code directory (or c:\path\to\dir directory) to the beginning of #INC for every script that is executed in the same environment.
Also see: Installing perl dependency automatically in perl

Can't locate Moo.pm in #INC

I am trying to run a .pm program in dzsoft perl editor. but i got this error
Can't locate Moo.pm in #INC (#INC contains: C:\Users\123\Desktop\ C:/Perl64/site/lib C:/Perl64/lib .) at UniNE.pm line 5.
My interpertor is ActivePerl-5.18.2.1802-MSWin32-x64-298023
how can I add moo.pm to lib?
This error means you've got a line that says use Moo; and it can't find it. The first question is - have you installed 'Moo'? If not, then:
perl -MCPAN -e shell
install Moo
This may take a bit of faffing with ActivePerl, so you may want to try and use ppm instead. If you do definitely have it installed, then I would suggest the next port of call is to try and figure out where it ended up - search for Moo.pm in your local filesystem, and compare that against your #INC path. You may find permissions are the root cause, and it's unreadable by your perl user.
I should install Moo module first. Try from cmd-line: cpan Moo

Perl Execution error

I just upgraded my Active Perl Version. If I call any Perl script through the windows command prompt or through UltraEdit (Text Editor) I am able to execute it perfectly but if I call it through cygwin terminal I am getting this error -
Can't locate Date/Pcalc.pm in #INC (#INC contains:
/usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int
/usr/lib/perl5/site_perl/5.14
/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int
/usr/lib/perl5/vendor_perl/5.14
/usr/lib/perl5/5.14/i686-cygwin-threads-64int /usr/lib/perl5/5.14
/usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/5.10
/usr/lib/perl5/site_perl/5.8 .) at Test.pl line 3. BEGIN
failed--compilation aborted at Test.pl line 3.
Even though the PCalc module is installed, it is looking in the wrong path for the PCalc.pm file. Any thoughts on how to resolve this and what it means ?
Any help is much appreciated ! Thanks.
Are you referencing the correct Perl ? i.e. are you picking up the Cygwin Perl installation as opposed to the ActiveState version ?
If you're referencing the correct Perl, then you should amend your PERL5LIB environment variable to reflect your local installation of Date/Pcalc.pm. See here for more details.

Using XPath with Perl

I am trying to replicate what my C#/XPath code does on Linux using Perl. I copied and pasted the code in Example 8-6 in Perl & XML. If I understand right, I should be able to run that Perl code, put this code in terminal
xmlPerl.pl mydatafile.xml "/inventory/category/item/name"
But when I try to run the Perl file, it doesn't work. Here is the error:
[root#Perl ~]# perl xmlPerl.pl
Can't locate XML/XPath.pm in #INC (#INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at xmlPerl.pl line 3.
BEGIN failed--compilation aborted at xmlPerl.pl line 3.
What am I doing wrong? I think it has something to do with the XML and XPath names in the beginning of my code. Do I need to install something to use the XPath framework? I am running on RedHat 5.5.
From perldiag:
Can't locate %s
You said to do (or require, or use) a file that couldn't be found. Perl looks for the file in all the locations mentioned in #INC, unless the file name included the full path to the file. Perhaps you need to set the PERL5LIB or PERL5OPT environment variable to say where the extra library is, or maybe the script needs to add the library name to #INC. Or maybe you just misspelled the name of the file. See require in perlfunc and lib.
You don't have installed XML::XPath module, or Perl not found it. Install module with CPAN:
> cpan XML::XPath
or with package manager:
> apt-get install libxml-xpath-perl
Or if it already installed say where it is with PERL5LIB environment variable:
> PERL5LIB=/path/to/lib perl ...
#INC variable:
BEGIN {
unshift(#INC, '/path/to/lib');
}
or lib pragma:
use lib '/path/to/lib';
That's the standard error that comes from trying to use a module that isn't installed. You should install it.
Ideally use the OS package for it; for example on a debian-derived OS (such as Debian or Ubuntu)
$ apt-get install libxml-xpath-perl
Failing that, you can install it as usual using CPAN
$ cpan XML::XPath
The answer is in the first part of your error:
Can't locate XML/XPath.pm
In Perl, the huge benefit is from using modules, or libraries, that others have written for you and you can reuse. In this case, someone has written a module called XML::XPath (in Perl, the path is delineated by '::') and you just need to install it. The easiest way to install it is via cpan, it's a tool that comes installed with most Perl installations. Just run:
cpan
(you'll be dropped into a different command prompt)
install XML::XPath
This will go out and fetch XML::XPath, unpack it, generate the Makefile, check for dependencies (and install any that are missing), make it, test it, and install it for you. Look here for more information on using CPAN.