Can't locate LWP/Simple.pm in #INC [duplicate] - perl

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What's the easiest way to install a missing Perl module?
I'm attempting to run a Perl script to convert SCXML to Graphviz DOT. I modified the first line of the script to:
#!/usr/bin/env perl
and chmod +x the file. When I run it via ./scmxl2dot.pl I see the following error output:
Can't locate LWP/Simple.pm in #INC (#INC contains: /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/site_perl/5.12.3 /opt/local/lib/perl5/vendor_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/vendor_perl/5.12.3 /opt/local/lib/perl5/5.12.3/darwin-multi-2level /opt/local/lib/perl5/5.12.3 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendor_perl .) at ./scmxml2dot.pl line 14.
BEGIN failed--compilation aborted at ./scmxml2dot.pl line 14.
Line 14 of the file is use LWP::Simple;
How do I:
Find out if I have this thing (module?) installed, and/or
Get LWP::Simple and make it available to the script?
This is running under OS X 10.7.3 and Perl 5.12.3 (as seen in the error).

You're already determined that you don't have it (somewhere it can be found).
perl -MCPAN -e'install "LWP::Simple"'

Execute the following from the command line:
perl -MLWP::Simple -e 1
If you don't get any output from the above command then the module is installed; if you get an error, it's not installed
to install use
perl -MCPAN -e'install "LWP::Simple"'
When perl encounters use My::Module it goes over the elements of the built-in #INC module that contains directory names. In each directory it check if there is a subdirectory called "My" and if in that subdirectory there is a file called "Module.pm".
check where LWP::Simple module is installed on your system and type below line just above the use LWP::Simple statement of your code.
use lib '/usr/local/module';
use LWP::Simple;

Take a look at the Perldoc webpage. This will tell you which modules are standard Perl modules and which ones aren't.
You can also use the perldoc command to find out if a Perl module is installed, and if it is, its documentation.
$ perldoc LWP::Simple
(If Perldoc doesn't execute as a command do ls -l /usr/bin/perl*. On Macs, some of the Perl commands don't have the execute bit turned on. To turn it on, do sudo chmod a+x /usr/bin/perl).
It just happens the LWP::Simple isn't a standard Perl module, and if you don't have it, you'll have to install it. Most people have already told you about cpan. Unfortunately, by default, the Mac doesn't have the needed command line development tools installed. You'll have to install them.
Once they're installed, you can use the cpan command to install LWP::Simple:
$ sudo cpan #Run cpan and configure it. It takes about 3 minutes
cpan> install LWP::Simple
cpan> exit

Related

Why installed programs with perl modules hardcode perl version?

When we install module this module can ship executable which is installed into local/bin directory.
if we spy into installed script we can notice that perl version is hardcoded:
/home/user/t/local/bin/mojo
#!/home/user/perl5/perlbrew/perls/perl-5.35.1/bin/perl5.35.1
Why perl version is hard coded?
I expect it should be /usr/bin/env perl:
$ which cpanm
/home/user/perl5/perlbrew/bin/cpanm
$ cat $(which cpanm) | less
#!/usr/bin/env perl
I expect it should be /usr/bin/env perl:
In this case it would take the Perl installation currently in the path. This might be a different Perl installation compared to what was used to install the application modules. In this case running the application might fail due to missing modules. Or it might show strange behavior since the installed modules have a different version than expected by application and thus can show different behavior.
For example imagine the case when there are two perl installations at your system. And when you install script with first perl you you can not run it with second perl, because second perl lacks modules available from first one.
It should have the path of the Perl with which it was installed.
This is the perl for which its dependencies has been installed.
This is the perl with which it has been tested.
If the script was made to rely on the environment as you suggest, it could pick up a different perl, and that would very likely cause it to fail.
For example, let's take a tool which has a shebang line of
#!/home/ikegami/usr/perlbrew/perls/5.34.0t/bin/perl -w
Regardless of the environment, it works fine.
$ /home/ikegami/usr/perlbrew/perls/latest/bin/tpage \
--define USER=World \
<<<'Hello, [% USER %]!'
Hello, World!
Now let's simulate the following shebang line:
#!/usr/bin/env perl -w
It fails misearbly despite the tool being correctly installed.
$ /usr/bin/env perl -w /home/ikegami/usr/perlbrew/perls/latest/bin/tpage \
--define USER=World \
<<<'Hello, [% USER %]!'
Can't locate Template.pm in #INC (you may need to install the Template module) (#INC contains: /home/ikegami/usr/perlbrew/perls/5.28.2t/lib/site_perl/5.28.2/x86_64-linux-thread-multi /home/ikegami/usr/perlbrew/perls/5.28.2t/lib/site_perl/5.28.2 /home/ikegami/usr/perlbrew/perls/5.28.2t/lib/5.28.2/x86_64-linux-thread-multi /home/ikegami/usr/perlbrew/perls/5.28.2t/lib/5.28.2) at /home/ikegami/usr/perlbrew/perls/latest/bin/tpage line 27.
BEGIN failed--compilation aborted at /home/ikegami/usr/perlbrew/perls/latest/bin/tpage line 27.
This is an unreliable solution subject to effects at a distance. For the same reason we scope variables, we should avoid env.
The story is different for self-contained scripts, but a self-contained script wouldn't be installed using ExtUtils::MakeMaker or Module::Build (the modules setting the shebang line), so such scripts aren't relevant here.
Seems correct question to my problem was: How to prevent perl from hard coding its version at shebang?
TLDR;
export PERL_MM_SHEBANG=relocatable
After reading article #Håkon Hægland adviced and reading #38
Now I see that there is two scenario:
when script is installed into system
when script is installed into application local/bin directory.
My case is second.
So for this case I should simultaneously set environment variable PERL_MM_SHEBANG to relocatable when I set current perl into path
This env variable implemented here

Installing Perl Module in specified directory

I am trying to install one of the Perl module in my server (ubuntu droplet from Digital Ocean). I wanted this module to be installed in /home/vinod/my_test_folder/perl_practice/scripts/lib/ directory which I have already created.
This is specific to one module. I don't want to install it in default path like /usr/bin/perl. I wanted it to be installed in above mentioned path.
Here are the list of commands which I executed to install the Email::Reply perl module.
Downloaded module from metacpan
tar xvfz Email-Reply-1.204.tar.gz
cd Email-Reply-1.204/
perl Makefile.PL PREFIX=/home/vinod/my_test_folder/perl_practice/scripts/lib/
su
<password_for_root>
make
make test
make install
When I execute make install command the following output got displayed on terminal screen
Manifying 1 pod document
Installing /home/vinod/my_test_folder/perl_practice/scripts/lib/share/perl/5.26.1/Email/Reply.pm
Installing /home/vinod/my_test_folder/perl_practice/scripts/lib/man/man3/Email::Reply.3pm
Appending installation info to /home/vinod/my_test_folder/perl_practice/scripts/lib//lib/x86_64-linux-gnu/perl/5.26.1/perllocal.pod
And I could see the module got installed in /home/vinod/my_test_folder/perl_practice/scripts/lib/share/perl/5.26.1/Email/Reply.pm path, which is not right path which I mentioned in PREFIX=.
Strange thing here I wrote one small script which uses Email::Reply module by mentioning module path in shebang line
Code below:
#!/usr/bin/perl -I/home/vinod/my_test_folder/perl_practice/scripts/lib/share/perl/5.26.1/
use EMail::Reply;
print "Hi\n";
still its throws an error
Can't locate EMail/Reply.pm in #INC (you may need to install the EMail::Reply module) (#INC contains: /home/vinod/my_test_folder/perl_practice/scripts/lib/share/perl/5.26.1/ /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at test.pl line 3.
BEGIN failed--compilation aborted at test.pl line 3.
I want this module to be installed in /home/vinod/my_test_folder/perl_practice/scripts/lib/
How to achieve this. Please help me.
This is what local::lib can be used for, and cpanm supports it by default:
$ cpanm -l /home/vinod/my_test_folder/perl_practice/scripts Email::Reply
This will install it to /home/vinod/my_test_folder/perl_practice/scripts/lib/perl5.
Alternatively you can recreate the options local::lib sets for this case, the important one for this case is PERL_MM_OPT.
$ env PERL_MM_OPT='INSTALL_BASE=/home/vinod/my_test_folder/perl_practice/scripts' cpanm Email::Reply
Importantly, note that all of this is case sensitive, you must use Email::Reply;.

Running perl test in intellij: Can't load module PassEnv at

I want to created perl modules in intellij derived by Tests. I created following test in a new project as shown below
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
done_testing();
But when i am trying to run the test (Shift+Alt+F10), it fails with below error
Testing started at 10:51 ...
C:/Strawberry/perl/bin\perl.exe C:/Strawberry/perl/bin/prove.bat -PPassEnv --formatter TAP::Formatter::Camelcade --merge --recurse --jobs 1 D:/workspace/code/repo/Modules/ImageUtilities/ReaConverterTest.t
Can't load module PassEnv at C:/Strawberry/perl/bin/prove.bat line 26.
Process finished with exit code 2
But when I run the test from the command line it works fine
$ perl -w ReaConverterTest.t
1..0
I see that there was an issue reported with intellij perl plugin(https://github.com/Camelcade/Perl5-IDEA/issues/1966) but it is closed. Looks like it was fixed in 2019.1 Perl but I am clueless why it's failing for me.
Any idea on how to fix this?
PS: I am using Git-Bash to run Perl scripts, IntelliJ using strawberry Perl installation on windows as Perl interpreter.
Update
When i run the script by adding "use PassEnv" it fails as there is no such module Searching from intellij also results in "no such module"
perl -w ReaConverter.t
Can't locate PassEnv.pm in #INC (you may need to install the PassEnv module) (#INC contain
s: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/sha
re/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at ReaConverter.
t line 6.
BEGIN failed--compilation aborted at ReaConverter.t line 6.
Because of the -PPassEnv option used, prove attempts to load App::Prove::Plugin::PassEnv. It hasn't been installed. Simply install the module.
Note: You want to install it using Strawberry Perl, so the following appears to be the appropriate command from your preferred shell:
/c/Strawberry/perl/bin/cpanm App::Prove::Plugin::PassEnv

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

Module Installation errors when trying to use local::lib and CPAN

I am trying to use local::lib as I don’t have admin rights on the system and I want to download and install a local library. I ran following:
perl Makefile.PL --bootstrap
make test && make install
echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc
After this I tried to download the Module via cpan
by running perl -MCPAN -e shell install netAddr::IP but when i am running my program it's giving an error:
Can't locate NetAddr/IP.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 .) at agha.pl line 8.
BEGIN failed--compilation aborted at agha.pl line 8.
I took that to mean the module is not installed... So I again tried to go through CPAN, but now it's giving an error (this is in Linux):
-bash-3.2$ perl -MCPAN -e shell
There seems to be running another CPAN process (pid 15611). Contacting...
Other job is running.
You may want to kill it and delete the lockfile, maybe. On UNIX try:
kill 15611
rm /homes/ar312/.cpan/.lock
From the local::lib documentation:
After writing your shell configuration file, be sure to re-read it to get the changed settings into your current shell's environment.
You forgot to do so.
In all seriousness, save yourself a ton of time and trouble by installing perlbrew.
perlbrew is a tool to manage multiple perl installations in your $HOME directory. They are completely isolated perl universes. This approach has many benefits:
No need to run sudo to install CPAN modules, any more.
Try the monthly released new perls.
Learn new language features.
Test your production code against different perl versions.
Leave vendor perl (the one that comes with OS) alone