Why does `use GD::Graph::pie;` fail even though CPAN says that GD::Graph::pie is installed and up to date? - perl

I'm trying to run a script called honeydsum.pl. It is failing a test and insisting I do not have GD::Graph::pie installed. The test that fails is:
unless (eval "use GD::Graph::pie; 1") {
die "$program_name: please install GD::Graph::pie.";
}
Thus it gives the output:
honeydsum.pl: please install GD::Graph::pie. at ./honeydsum.pl line 65
Where I am confused is that when I check on CPAN it says GD::Graph::pie is up to date:
cpan[5]> install GD::Graph::pie
GD::Graph::pie is up to date (1.21).
I'm not a Perl expert, but is there a reason it would fail the test even if the module is installed?
Output from cpan -D:
~# cpan -D GD::Graph::pie
Reading '/root/.cpan/Metadata'
Database was generated on Mon, 06 Mar 2017 21:17:02 GMT
GD::Graph::pie
-------------------------------------------------------------------------
(no description)
R/RU/RUZ/GDGraph-1.54.tar.gz
/root/perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/GD/Graph/pie.pm
Installed: 1.21
CPAN: 1.21 up to date
Ruslan U. Zakirov (RUZ)
Ruslan.Zakirov#gmail.com
There was no output from
perl -MGD::Graph::pie -e1
In my /usr/share/ directory I have the following related to perl:
perl/5.22
perl/5.22.2
perl5
I'm not sure what a proper perl installation would have put in this directory.

The script is using the system perl, but you installed GD::Graph::pie for a perlbrew installation. If you want the script to use your perlbrew perl, change the shebang from
#! /usr/bin/perl -T -w
to
#! /root/perl5/perlbrew/perls/perl-5.20.1/bin/perl -T -w

Related

find correct version of Perl library function List::Util

MaxMind GeoIP was working on Mojave, called from Perl.
I tried to upgrade my macOS installation from Perl 5.26 to 5.30.
Used MacPorts to install and activate 5.30, and then
used CPAN to install Perl modules.
Several ports got errors trying to install. I had to force them.
GeoIP2::Database::Reader (2.006002)
MaxMind::DB::Reader (1.000014)
NetAddr::IP (4.079)
Tried it out and it failed because a Perl module was down-rev.
[thvv lib]$ ipcity
Could not find a suitable MaxMind::DB::Reader implementation: List::Util version 1.56 required--this is only version 1.5 at /opt/local/lib/perl5/site_perl/5.30/List/AllUtils.pm line 8.
In CPAN I tried to install List::Util. It says version 1.56 is already installed.
cpan[4]> i List::Util
Module id = List::Util
CPAN_USERID PEVANS (Paul Evans <leonerd#leonerd.org.uk>)
CPAN_VERSION 1.56
CPAN_FILE P/PE/PEVANS/Scalar-List-Utils-1.56.tar.gz
MANPAGE List::Util - A selection of general-utility list subroutines
INST_FILE /opt/local/lib/perl5/site_perl/5.30/darwin-thread-multi-2level/List/Util.pm
INST_VERSION 1.56
my environment all points to Perl version 5.30
perl --version
This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level
env | grep 5.30
PERL5LIB=/Users/thvv/bin:/opt/local/lib/perl5/5.30
PERL_MB_OPT=--install_base "/opt/local/lib/perl5/5.30"
PERL_LOCAL_LIB_ROOT=/opt/local/lib/perl5/5.30
PERL_MM_OPT=INSTALL_BASE=/opt/local/lib/perl5/5.30
How can I get List::AllUtils to find the version of List::Util that is installed?
(Friday 23 July 2021) Added info as requested:
[thvv lib]$ head -1 ~/bin/ipcity
#!/usr/local/bin/perl -I/usr/home/thvv/bin
-- (tried it without the -I clause and got the same output)
[thvv bin]$ perl -MList::Util=999 -e1
List::Util version 999 required--this is only version 1.5 at /opt/local/lib/perl5/5.30/Exporter/Heavy.pm line 125.
BEGIN failed--compilation aborted.
--- looking in my file system for the module
[thvv bin]$ ls -l /opt/local/lib/perl5/5.30//darwin-thread-multi-2level/List/
total 16
-r--r--r--+ 1 root admin 21126 Jul 1 06:52 Util.pm
drwxr-xr-x+ 3 root admin 96 Jul 18 12:05 Util/
[thvv bin]$ ls -l /opt/local/lib/perl5/5.30//darwin-thread-multi-2level/List/Util
total 0
-r--r--r--+ 1 root admin 1018 Jul 1 06:52 XS.pm
--- I also invoked cpan and did a 'force install List::Util'
Running install for module 'List::Util'
Fetching with LWP:
http://www.cpan.org/authors/id/P/PE/PEVANS/CHECKSUMS
Checksum for /var/root/.cpan/sources/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.56.tar.gz ok
Scanning cache /var/root/.cpan/build for sizes
............................................................................DONE
Configuring P/PE/PEVANS/Scalar-List-Utils-1.56.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for List::Util
Writing MYMETA.yml and MYMETA.json
PEVANS/Scalar-List-Utils-1.56.tar.gz
/opt/local/bin/perl5.30 Makefile.PL -- OK
Running make for P/PE/PEVANS/Scalar-List-Utils-1.56.tar.gz
cp lib/Sub/Util.pm blib/lib/Sub/Util.pm
cp lib/List/Util.pm blib/lib/List/Util.pm
cp lib/List/Util/XS.pm blib/lib/List/Util/XS.pm
cp lib/Scalar/Util.pm blib/lib/Scalar/Util.pm
Running Mkbootstrap for Util ()
chmod 644 "Util.bs"
"/opt/local/bin/perl5.30" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
"/opt/local/bin/perl5.30" "/opt/local/lib/perl5/5.30/ExtUtils/xsubpp" -typemap '/opt/local/lib/perl5/5.30/ExtUtils/typemap' ListUtil.xs > ListUtil.xsc
mv ListUtil.xsc ListUtil.c
/usr/bin/cc -c -fno-common -DPERL_DARWIN -pipe -Os -fno-strict-aliasing -fstack-protector-strong -I/opt/local/include -DPERL_USE_SAFE_PUTENV -Wno-error=implicit-function-declaration -O3 -DVERSION=\"1.56\" -DXS_VERSION=\"1.56\" "-I/opt/local/lib/perl5/5.30/darwin-thread-multi-2level/CORE" -DPERL_EXT -DUSE_PPPORT_H ListUtil.c
rm -f blib/arch/auto/List/Util/Util.bundle
/usr/bin/cc -bundle -undefined dynamic_lookup -L/opt/local/lib -Wl,-headerpad_max_install_names -fstack-protector-strong ListUtil.o -o blib/arch/auto/List/Util/Util.bundle \
\
chmod 755 blib/arch/auto/List/Util/Util.bundle
Manifying 4 pod documents
PEVANS/Scalar-List-Utils-1.56.tar.gz
/usr/bin/make -- OK
Running make test for PEVANS/Scalar-List-Utils-1.56.tar.gz
"/opt/local/bin/perl5.30" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
PERL_DL_NONLAZY=1 "/opt/local/bin/perl5.30" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00version.t ......... ok
t/any-all.t ........... ok
t/blessed.t ........... ok
t/dualvar.t ........... ok
t/exotic_names.t ...... ok
t/first.t ............. ok
t/getmagic-once.t ..... ok
t/head-tail.t ......... ok
t/isvstring.t ......... ok
t/lln.t ............... ok
t/max.t ............... ok
t/maxstr.t ............ ok
t/mesh.t .............. ok
t/min.t ............... ok
t/minstr.t ............ ok
t/openhan.t ........... ok
t/pair.t .............. ok
t/product.t ........... ok
t/prototype.t ......... ok
t/readonly.t .......... ok
t/reduce.t ............ ok
t/reductions.t ........ ok
t/refaddr.t ........... ok
t/reftype.t ........... ok
t/rt-96343.t .......... ok
t/sample.t ............ ok
t/scalarutil-proto.t .. ok
t/shuffle.t ........... ok
t/stack-corruption.t .. ok
t/subname.t ........... ok
t/sum.t ............... ok
t/sum0.t .............. ok
t/tainted.t ........... ok
t/uniq.t .............. ok
t/uniqnum.t ........... ok
t/weak.t .............. ok
t/zip.t ............... ok
All tests successful.
Files=37, Tests=2144, 4 wallclock secs ( 0.24 usr 0.10 sys + 2.88 cusr 0.42 csys = 3.64 CPU)
Result: PASS
Lockfile removed.
PEVANS/Scalar-List-Utils-1.56.tar.gz
/usr/bin/make test -- OK
Running make install for PEVANS/Scalar-List-Utils-1.56.tar.gz
"/opt/local/bin/perl5.30" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
Manifying 4 pod documents
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Appending installation info to /opt/local/lib/perl5/5.30/darwin-thread-multi-2level/perllocal.pod
PEVANS/Scalar-List-Utils-1.56.tar.gz
/usr/bin/make install -- OK
(23 July 2021, more)
[thvv bin]$ which perl
/opt/local/bin/perl
[thvv bin]$ ls -l /opt/local/bin/perl
lrwxr-xr-x 1 root wheel 8 Jul 21 12:28 /opt/local/bin/perl# -> perl5.30
[thvv bin]$ file `which perl`
/opt/local/bin/perl: Mach-O 64-bit executable x86_64
(12:59 EDT 23 July 2021) tried looking at /opt/local/lib/perl5/5.30//darwin-thread-multi-2level/List/Util/XS.pm
this seems to be where the 1.5 comes from.
force installed it, no change
package List::Util::XS;
use strict;
use warnings;
use List::Util;
our $VERSION = "1.50"; # FIXUP
$VERSION = eval $VERSION; # FIXUP
1;
[snipped pod]
I tried editing /opt/local/lib/perl5/site_perl/5.30/List/AllUtils.pm to change 1.50 to 1.56. restarted the machine for luck. still fails at List/AllUtils.pm line 8, saying the current version is 1.50.
(24 Jul 2021 08:13 EDT) as requested by #ikegami
[thvv#Uly2 ~]$ echo 'o conf' | cpan | grep 'make\|mbuild'; set | grep ^PERL
make [/usr/bin/make]
make_arg []
make_install_arg []
make_install_make_command [sudo /usr/bin/make]
makepl_arg []
mbuild_arg []
mbuild_install_arg []
mbuild_install_build_command [sudo ./Build]
mbuildpl_arg []
PERL5LIB=/Users/thvv/bin:/opt/local/lib/perl5/5.30
PERL_LOCAL_LIB_ROOT=/opt/local/lib/perl5/5.30
PERL_MB_OPT='--install_base "/opt/local/lib/perl5/5.30"'
PERL_MM_OPT=INSTALL_BASE=/opt/local/lib/perl5/5.30
ok, I deleted Perl 5.30, installed 5.34, reloaded my Perl Modules.
It still fails.
Could not find a suitable MaxMind::DB::Reader implementation: List::Util version 1.56 required--this is only version 1.55 at /opt/local/lib/perl5/site_perl/5.34/List/AllUtils.pm line 8.
BEGIN failed--compilation aborted at /opt/local/lib/perl5/site_perl/5.34/List/AllUtils.pm line 8.
The "use" line that failed in List::AllUtils looked for List::Util version 1.56. The .pm file for List::Util is in
/opt/local/lib/perl5/site_perl/5.34/darwin-thread-multi-2level/List/Util.pm
and calls
XSLoader::load('List::Util', $XS_VERSION)
with version 1.56. That in turn tries to invoke
/opt/local/lib/perl5/site_perl/5.34/darwin-thread-multi-2level/auto/List/Util/Util.bundle
which is a Mac binary file. It appears that XSLoader has not loaded the binary version of List::Util.
Aha. I see that /opt/local/lib/perl5/5.34 and /opt/local/lib/perl5/site_perl/5.34 are different directories with different contents. The files I loaded with CPAN went into site_perl/5.34. But List::Util is in 5.34.
Only one program had substantive code changes between the two directories.
So, on the Mac, should I change /opt/local/lib/perl5/site_perl/5.34/ to be a symlink to /opt/local/lib/perl5/5.34/ ?
ipcity uses /usr/local/bin/perl, which is a symlink to /opt/local/bin/perl. This is the first perl found in the path. Should we check the shebang of cpan, we'd find the same perl referenced (as evidenced by the output of the installation attempt). It's possible you have more than one installation of Perl, but there's one only involved here. Therefore, te issue isn't one of installing List::Util for the wrong perl.
Loading List::Util loads version reveals a version 1.5 was loaded. Yet version 1.56 was installed. This means the module was installed in a non-standard location, but perl wasn't told to look at that location.
Your environment informs module installers ExtUtils::MakeMaker and Module::Build to install modules under /opt/local/lib/perl5/5.30. Specifically, it informs the installers to install the .pm file in /opt/local/lib/perl5/5.30/lib/perl5 (or the corresponding arch dir), but perl is not told to look in this directory; it is told to look in /opt/local/lib/perl5/5.30. This is wrong, and the crux of the problem.
Fix PERL5LIB.
That said, it doesn't make sense to set PERL_MB_OPT
and PERL_MM_OPT when using a perl in /opt. The default installation paths of your perl you should already be sensible. You can see what they are using
perl -V:'.*inst.*'
Finally, if PERL_MB_OPT
and PERL_MM_OPT aren't set, it doesn't make sense to set PERL5LIB or PERL_LOCAL_LIB_ROOT either.
I suspect you should unset all four of those variables.

Perl Compiling PP issue in Strawberry Perl [duplicate]

I've been using pp
https://metacpan.org/pod/pp
A while ago!
However when hiring another hosting, when I run the pp command the scripts do not run on the server
CentOS Linux release 7.9.2009 (Core)
Perl v 5.32.1
Command using pp, host old
$ pp -x -c name.pl
When running
./a.out
Unable to open html entities file (/tmp/par-726f6f74/cache-78cdefedff4d2afddea0035addc3b570c8f0bfd5/inc/lib/Mojo/resources/html_entities.txt): No such file or directory at script / name.pl line 13.
Compilation failed in require at script / name.pl line 13.
BEGIN failed - compilation aborted at script / name.pl line 13.
And when I run ./name.pl it runs normally.
Any suggestion?
name.pl
#!/usr/bin/perl
use FindBin qw($Bin);
use lib ("$Bin");
use DBI;
use Number::Format;
use Encode qw(decode encode);
use File::Basename;
use Mojo::Util qw(b64_encode b64_decode url_escape url_unescape);
use Mojo::JSON qw(decode_json encode_json);
use Image::ExifTool;
use LWP;
print "Test Mojo";
This same command works normally in version 5.28 on another server/hosting
You need to add the file html_entities.txt to the archive.
The following seems to work for me:
Find the location of the file:
$ perl -MMojo::Util -MFile::Basename=dirname -E '$fn = (dirname $INC{"Mojo/Util.pm"}) . "/resources/html_entities.txt"; say $fn'
/home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Mojo/resources/html_entities.txt
Copy the file to a local directory:
$ mkdir -p ./lib/Mojo/resources/
$ cp /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Mojo/resources/html_entities.txt ./lib/Mojo/resources/
Add the file to the archive
$ pp -x -c -a lib/Mojo/resources/html_entities.txt name.pl

Running a Perl script from crontab when you use Perlbrew

I have tried the following and find it to work. This is done with a non-privileged user. First find out where your perl command is:
# which perl
Then check the value of PERL5LIB:
# echo $PERL5LIB
Then, at the crontab file of the user, do something like:
MAILTO=<my email address for the jobs output>
HOME=/home/myhome
PERL5LIB=/home/myhome/perl5/lib/perl5
0 2 * * * $HOME/<rest of path to perl>/perl $HOME/<path to my perl script> arg1 ...
This will run a job at 2am and seems to find all Perl libs correctly. My question is: is this complete and portable? Is there a better way?
I have seen a number of bash and perl scripts out there that are supposed to prepare the environment for the execution of a Perl script, but this seems to suffice. Any advice will be welcome!
EDIT: From the comments to the question, it seems that I am using a "bad" mixture of Perlbrew and local::lib. The way to make sure libraries get installed inside a particular Perlbrew version is answered here: How do I install CPAN modules while using perlbrew?. Both cpan and cpanm will install under PERL5LIB when you are using local::lib unless you explicitly tell them to do otherwise. Also cpanm seems to be better suited to working along with Perlbrew.
The shebang (#!) line of the script should point to the (perlbrew-installed) perl it is meant to run under. (This should be done as part of installing the script.) That's all you need.
0 2 * * * /path/to/script arg1 ...
If you already have multiple perl installations managed with perlbrew the easiest approach is to just use perlbrew exec to run your script. The -q and --with options allow you to silence superfluous output and select the specific version of perl to run the script/job. Try something like:
perlbrew exec perl -E 'say "Hello from $]\n"' (this will show errors from older versions (< 5.10) of perl that don't have the -E switch enabled by default).
perlbrew exec -q --with 5.26.1 perl -E 'say "Hello from $]\n"' (this will run the command and suppress informational output).
perlbrew exec -q --with 5.26.1 perl ~/script_from_heaven.pl (runs the script with the perl version requested).
perlbrew exec -q --with 5.26.1 ~/script_from_heaven.pl (runs the script with the perl version requested or hard-coded in the script's shebang line).
I tend to explicitly set PERL5LIB and use local::lib only when I need them or for certain users or environments where I exclusively install all CPAN modules in $HOME/perl5/lib/perl5 (a full application deployment, say). Otherwise I find running perl from perlbrew pretty convenient.
A couple of things I've found helpful: setting an alias for perlbrew environments that you want to keep stable for a particular use can be a useful way to manage multiple perls:
~/$ perlbrew alias create perl-5.24.0 stable-cronperl
~/$ perlbrew list
perl-5.8.9
perl-5.10.1
perl-5.24.0
cperl-cperl-5.26.1
stable-cronperl (5.24.0)
perl-5.26.1
NB: however the alias is only useful/useable as a stable #! shebang anchor for use at the top of your scripts if you want to make them executable:
#!/home/cronic/perl5/perlbrew/perls/stable-cronperl/bin/perl
You can't refer to an alias using --with for example:
perlbrew exec --with stable-cronperl ~/smart_comments.pl
Reporting this as either a documentation issue or a bug is on my to do list.

Error: Can't locate File/HomeDir.pm in #INC

I use a Mac OS X 10.8, and want to run the latexindent.pl perl script on my latex files. This script is made by https://github.com/cmhughes/latexindent.plx. When I run this script on a latexfile I get this error message:
Can't locate File/HomeDir.pm in #INC (#INC contains: /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 .) at helloworld.pl line 10.
BEGIN failed--compilation aborted at helloworld.pl line 10.
It seems that I am missing the File::HomeDir module in perl so I tried to download it using:
sudo perl -MCPAN -e 'install File::HomeDir',
I get the following error:
Can't locate object method "install" via package "File::HomeDir".
I managed to install the YAML::Tiny package without any problems.
I tried to run:
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use FindBin;
6 use YAML::Tiny;
7 use File::Copy;
8 use File::Basename;
9 use Getopt::Std;
10 use File::HomeDir;
11
12 print "hello world";
13 exit;
and got the same Error message as above...
Do anyone know what to do?
sudo perl -MCPAN -e 'install "File::HomeDir"'
^ ^
I had a similar problem. I just ran these commends, and it worked for me
sudo cpan -i File::HomeDir
then
sudo cpan -i Unicode::GCString
Basically, I will run latexindent file_name.tex, then an error message will appear that says you may need to install the XXXX module then I install the XXXX module using sudo cpan -i XXXX

Why won't a module installed by `cpanm` be recognized?

I installed perl-5.12.2 using perlbrew:
perlbrew install perl-5.12.2 -D=usethreads -D=useithreads -D=uselargefiles -f
I then switched to this version and installed IPC::System::Simple using cpanm.
However, when I try to run my script I get:
Can't locate IPC/System/Simple.pm in #INC (#INC contains: /home/dave/workspace/proj1/scripts/bin/../lib /home/dave/src/bioperl-live /home/dave/perl5/perlbrew/perls/perl-5.12.2/lib/site_perl/5.12.2/x86_64-linux-thread-multi /home/dave/perl5/perlbrew/perls/perl-5.12.2/lib/site_perl/5.12.2 /home/dave/perl5/perlbrew/perls/perl-5.12.2/lib/5.12.2/x86_64-linux-thread-multi /home/dave/perl5/perlbrew/perls/perl-5.12.2/lib/5.12.2 .) at /home/dave/workspace/proj1/scripts/bin/../lib/createLayout.pm line 14.
I also found the following dir:
~/perl5/lib/perl5/x86_64-linux-thread-multi/auto/IPC/System/Simple
but it's empty (I have no idea if this means something).
Try this step-by-step guide, paying close attention to steps 7 and 8 (and optionally 9).
What does which cpanm from the command line show? For you it should report:
/home/dave/perl5/perlbrew/bin/cpanm
If thats OK then what does ls -l /home/dave/perl5/perlbrew/bin/cpanm show? It should be pointing to:
cpanm -> /home/dave/perl5/perlbrew/perls/current/bin/cpanm
And finally ls -l /Users/barry/perl5/perlbrew/perls/current should be pointing to the Perl you've switched to in perlbrew:
/home/dave/perl5/perlbrew/perls/current -> perl-5.12.2
All three of these must be like this otherwise something is wrong.
If its not then one likely issue is that cpanm is pointing to another installed Perl. You need to have cpanm installed for each version of perl under perlbrew:
perlbrew switch perl-5.12.2
curl -L http://cpanmin.us | perl - App::cpanminus
Now if which cpanm still doesn't show the perlbrew path then you have a $PATH precedence issue in your .bash_profile (or equivalent) file. This can be fixed by making sure that your perlbrew line...
source /home/dave/perl5/perlbrew/etc/bashrc
... in the profile file is after any other export $PATH lines.
After re-login back in you can confirm that this is right by doing echo $PATH and you should see perlbrew at the beginning (the left) of the path string, ie. something like this:
/home/dave/perl5/perlbrew/bin:/home/dave/perl5/perlbrew/perls/current/bin:/usr/bin:/bin:/usr/local/bin: