Installing Perl Module in specified directory - perl

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

Related

Building from Singularity recipes problems

I am a beginner in Singularity and I would like having help in building from a recipe.
I want to use GARM, a genome assemblies reconciliation tool, to reconciliate two genomes I have assembled. Since I am working on a HPC server, I don't have the permissions to install the required perl packages for this tool (which are Parallel::ForkManager and List::MoreUtils) and R. I found there are two possible solutions for that (and please tell me if I am wrong or if there are other things I can do):
install R and perl modules locally (but in this case I should change all the scripts references to them)
build a Singularity container containing all the dependencies needed and GARM, since the server has Singularity 2.6 installed.
I choosen the second solution and decided to use a recipe to build the container, which is the following:
Bootstrap: docker
From: ubuntu
%files
GARM_0.7.4
%post -c /bin/bash
apt-get update
apt-get install -y --force-yes perl build-essential cpanminus r-base
cpanm Parallel::ForkManager List::MoreUtils
export GARMBIN=/GARM_0.7.4/bin
export GARMLIB=/GARM_0.7.4/lib
export MUMBIN=/GARM_0.7.4/MUMmer3.22
export AMOSBIN=/GARM_0.7.4/amos-3.0.0/bin
export AMOSLIB=/GARM_0.7.4/amos-3.0.0/lib
%runscript
exec perl /GARM_0.7.4/GARM.pl
where GARM_0.7.4 is the folder downloaded containing everything the software needs, except R and perl modules.
I use sudo singularity build garm.simg recipe-garm to build the container.
Then using singularity run garm.simg --help to see if the container works, it comes out this:
Can't open perl script "/GARM_0.7.4/GARM.pl": Permission denied
Now, even if on the server I cannot use sudo, on my PC I tried anyway it with sudo singularity run garm.simg --help, and the output is:
Empty compile time value given to use lib at /GARM_0.7.4/GARM.pl line 12.
Can't locate GARM_main.pm in #INC (you may need to install the GARM_main module) (#INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /GARM_0.7.4/GARM.pl line 13.
BEGIN failed--compilation aborted at /GARM_0.7.4/GARM.pl line 13.
I don't know what is wrong. I can't get if the problem is the garm folder not copied inside the container so that the garm script can't be run, or if there are sintax problem in the recipe and the container does not run the script.
EDIT: added exports as README.txt from the tool suggests, but the situation does not change.

Making Perl CPAN's Pg module work on Amazon's AWS server

I´m trying to port a Perl legacy software to Amazon's AWS servers, but I keep running on problems when trying to make all the components I need work.
Currently, I have Perl up and running (version 5.16.3), and PostgreSQL (9.2.18) as my database with no problems. They both run fine separately, but I simply can't make them work together.
This legacy software uses Pg library (I'm not referring to DBD::Pg, just Pg). However, I'm not able to run a script that references that specific library. I get the following error:
Can't locate loadable object for module Pg 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 /var/www/cgi-bin) at /var/www/cgi-bin/teste.pl line 8.
After some research, I understand that I'm somehow missing a dependency that Pg requires to work properly. I opened Pg.pm script to check which what it uses, and tried to import those through CPAN as well.
I managed to import Exporter and Carp successfully through cpan but DynaLoader simply won't install - apparently it needs to be compiled??
What do I need to do to properly install Pg?
I have never used Pg, so let's try on my ArchLinux install.
$ curl -O https://cpan.metacpan.org/authors/id/M/ME/MERGL/pgsql_perl5-1.9.0.tar.gz
$ tar xvf pgsql_perl5-1.9.0.tar.gz
$ cd pgsql_perl5-1.9.0
$ perl Makefile.PL
$ perl Makefile.PL
Configuring Pg
Remember to actually read the README file !
please set environment variables POSTGRES_INCLUDE and POSTGRES_LIB
So, if you installed Pg, you had to have set those variables. Simplest would be to install your chosen distro's package for those libraries. On ArchLinux, the following command installs them for me:
$ sudo pacman -S postgresql-libs
Then:
$ POSTGRES_INCLUDE=/usr/include POSTGRES_LIB=/usr/lib perl Makefile.PL
Configuring Pg
Remember to actually read the README file !
OS: linux
Generating a Unix-style Makefile
Writing Makefile for Pg
Writing MYMETA.yml and MYMETA.json
The build works but I can't test because I do not have a Postgresql instance to connect to. However, this works:
$ perl -I blib/lib -I blib/arch -e 'use Pg; print "ok\n"'
ok
Note the -I switches above would not have been necessary had I chosen to install this module that was last updated 17 years ago.

Bugzilla 5.0 install on OpenShift - Can't locate parent.pm in #INC

Attempting to install Bugzilla on an OpenShift small gear. Using SSH to wget 5.0 tarball, untar-ing and running the checksetup.pl --check-modules script gives me this error:
Can't locate parent.pm in #INC (INC contains: . lib /var/openshift/[app-id]/app-root
/runtime/repo/libs /var/lib/openshift/[app-id]/perl/perl5lib/lib/perl5 /usr/local/lib64
/perl5 /usr/local/share/perl5 /usr/lib/lib64/perl5/vendor-perl /usr/share/perl5/vendor-perl
/usr/lib64/perl5 usr/share/perl5) at Bugzilla/Constants.pm line 14.
BEGIN failed--compilation aborted at Bugzilla/Constants.pm line 14.
Compilation failed in require at ./checksetup.pl line 27.
BEGIN failed--compilation aborted at ./checksetup.pl line 27.
Line 14 of Bugzilla/Constants.pm: `use parent qw(Exporter);`
Line 27 of ./checksetup.pl: `use Bugzilla::Constants;`
[app-id] in the paths is just a random string of hex digits used to identify an OpenShift application.
All help would be greatly appreciated. Thanks in advance!
That means either parent is not installed in your system or it's not a part of #INC.
Try perldoc -l parent to see if it's installed or not.
If it's installed then update PERL5LIB enviroment variable to add path to directory where module is installed.
If it's not installed then run cpan parent to install.
Also see:
How do I 'use' a Perl module in a directory not in #INC?
How to change #INC to find Perl modules in non-standard locations
Apparantly OpenShift has a cpan.txt file in the .openshift folder. Adding parent to that folder installed the required module.
#please install above packages:
[root#rsync ~]# yum install perl-parent -y

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

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.