I am not a perl expert (see this page), but for using a package, I have to run some perl commands. The command shows this error
$ perl Build.PL
Can't locate Module/Build.pm in #INC (#INC contains: /home/mahmood/src/bioperl-1.6.1 /home/mahmood/src/ensembl/modules
/home/mahmood/src/ensembl-compara/modules /home/mahmood/src/ensembl-variation/modules
/home/mahmood/src/ensembl-funcgen/modules /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 Build.PL line 20.
BEGIN failed--compilation aborted at Build.PL line 20.
I see this reply which offers running cpan Module::Build first to fix that error. As I run that command, I see a bunch of questions (text wizard) which asks me a mirror url. Then it interactively asks my permission to install the packages. It seems that default answers to the questions has such effect. I also, didn't find which question is responsible for that. Please see the full output at pastebin.
Is there any way to automatically install the module, so that I can put that in a script for future things.
UPDATE:
It seems that I have to enter the cpan.org url however in my previous attempt, I used mirror websites. I tried the three commands proposed in the reply, but still get the same error:
Please enter the URL of your CPAN mirror http://www.cpan.org
Configuration does not allow connecting to the internet.
Current set of CPAN URLs:
http://www.cpan.org
Enter another URL or RETURN to quit: []
New urllist
http://www.cpan.org
Please remember to call 'o conf commit' to make the config permanent!
cpan shell -- CPAN exploration and modules installation (v1.9402)
Enter 'h' for help.
cpan[1]> o conf build_requires_install_policy yes
build_requires_install_policy [yes]
Please use 'o conf commit' to make the config permanent!
cpan[2]> o conf prerequisites_policy follow
prerequisites_policy [follow]
Please use 'o conf commit' to make the config permanent!
cpan[3]> o conf commit
commit: wrote '/home/mahmood/.cpan/CPAN/MyConfig.pm'
cpan[4]> quit
No history written (no histfile specified).
Lockfile removed.
mahmood#cluster:Bio-DB-HTS$ perl Build.PL
Can't locate Module/Build.pm in #INC (#INC contains: /home/mahmood/src/bioperl-1.6.1 /home/mahmood/src/ensembl/modules /home/mahmood/src/ensembl-compara/modules /home/mahmood/src/ensembl-variation/modules /home/mahmood/src/ensembl-funcgen/modules /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 Build.PL line 20.
BEGIN failed--compilation aborted at Build.PL line 20.
If you want to install Module::Build into your system libraries, then it's probably far easier to use the pre-built package that is almost certainly available for your system.
If you're using a RedHat-like Linux distribution, try:
$ sudo yum install perl-Module-Build
(Try dnf instead of yum on newer versions of Fedora.)
If you're using a Debian-like Linux distribution, try:
$ sudo apt-get install libmodule-build-perl
Now that you've got cpan configured, you can change the configuration to bypass asking you to install each dependency.
On the command line (note the o characters are literal... they are not points):
cpan
o conf build_requires_install_policy yes
o conf prerequisites_policy follow
o conf commit
To see a description of each item before entering your response manually:
cpan
o conf init build_requires_install_policy
When a module declares another one as a 'build_requires' prerequisite
this means that the other module is only needed for building or
testing the module but need not be installed permanently. In this case
you may wish to install that other module nonetheless or just keep it
in the 'build_dir' directory to have it available only temporarily.
Installing saves time on future installations but makes the perl
installation bigger.
You can choose if you want to always install (yes), never install (no)
or be always asked. In the latter case you can set the default answer
for the question to yes (ask/yes) or no (ask/no).
<build_requires_install_policy>
Policy on installing 'build_requires' modules (yes, no, ask/yes,
ask/no)? [yes]
o conf init prerequisites_policy
The CPAN module can detect when a module which you are trying to build
depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Choosing
'follow' also sets PERL_AUTOINSTALL and PERL_EXTUTILS_AUTOINSTALL for
"--defaultdeps" if not already set.
Please set your policy to one of the three values.
<prerequisites_policy>
Policy on building prerequisites (follow, ask or ignore)? [follow]
After you've set them, don't forget to do a:
o conf commit
...to save your changes.
Now run:
cpan Module::Build
...and finally, run your build script:
./Build.PL
Related
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;.
I installed a CPAN module like this:
cpan Acme
According to the output, the installation was successful:
Running install for module 'Acme'
...
All tests successful.
Files=2, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.04 cusr 0.00 csys = 0.06 CPU)
Result: PASS
INGY/Acme-1.11111111111.tar.gz
/usr/bin/make test -- OK
Running make install
Manifying 1 pod document
Installing /home/foo/perl5/lib/perl5/Acme.pod
Installing /home/foo/perl5/lib/perl5/Acme.pm
Installing /home/foo/perl5/man/man3/Acme.3pm
Appending installation info to /home/foo/perl5/lib/perl5/x86_64-linux-thread-multi/perllocal.pod
INGY/Acme-1.11111111111.tar.gz
/usr/bin/make install -- OK
But when I try to use the module, I get an error:
$ perl -MAcme -e1
Can't locate Acme.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 .).
BEGIN failed--compilation aborted.
Why can't perl find the module even though it was installed successfully? How can I fix this?
The module was installed here:
/home/foo/perl5/lib/perl5/Acme.pm
But perl looks for modules in #INC, which in this case 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
.
(. refers to the current working directory.)
Since the module is not in #INC, perl can't find it without some help.
Why did CPAN install the module outside of #INC?
A common cause is configuring CPAN to bootstrap local::lib so that modules are installed in your home directory instead of in the system Perl directories. If you have CPAN 1.9463 or higher and you don't have write permissions in the default install path, the first time you run CPAN you will be prompted:
Warning: You do not have write permission for Perl library directories.
To install modules, you need to configure a local Perl library directory or
escalate your privileges. CPAN can help you by bootstrapping the local::lib
module or by configuring itself to use 'sudo' (if available). You may also
resolve this problem manually if you need to customize your setup.
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
[local::lib]
If you choose to bootstrap local::lib (the default), the module will be installed inside ~/perl5. You may also be prompted something like:
Would you like me to append that to /home/foo/.bashrc now? [yes]
If you choose yes (the default), some variables will be added to your .bashrc (or the equivalent for your shell) so that when you run CPAN in the future, modules will continue to be installed in your home directory:
PATH="/home/foo/perl5/bin${PATH+:}${PATH}"; export PATH;
PERL5LIB="/home/foo/perl5/lib/perl5${PERL5LIB+:}${PERL5LIB}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/foo/perl5${PERL_LOCAL_LIB_ROOT+:}${PERL_LOCAL_LIB_ROOT}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/foo/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/foo/perl5"; export PERL_MM_OPT;
How can I fix it?
If CPAN added the above environment variables to your .bashrc (or equivalent), the simplest thing to do is start a new shell (or source your .bashrc). This will set PERL5LIB so that perl can find modules installed in ~/perl5.
On the other hand, if you have sudo access and you want CPAN to install modules in the system Perl directories instead of in your home directory, delete the environment variable settings from your .bashrc (or equivalent), start the CPAN shell, and run:
o conf init
This will reset the CPAN configuration. You will be prompted again if you want to bootstrap local::lib; enter "sudo" instead. In general, I wouldn't recommend doing this; it's usually better to use your distro's package manager (e.g. yum, apt) to install modules in the system Perl directories.
Also see: How do I 'use' a Perl module in a directory not in #INC?
On Centos 7 /RedHat 7 this is caused by package perl-homedir. It sets the variables via /etc/profile.d. Remove it. Than everything is working as expected. Took me hours to find out why I wasn't able to rebuild a package from Epel or CentOS.
The solution I found is to locate /local/lib.pm in one of the #INC directories and delete it or rename it (to an extension other than 'pm'). Then, rename (to an extension other than 'sh' or 'csh') or delete /etc/profile.d/perl-homedir.sh.
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
I am trying to use Perl the first time on my system which is Ubuntu 12.04. I have Perl v.5.14.2 installed.
I looked up how to install Perl modules, so I started as follows:
$ perl -MCPAN -e shell
The wizard started configuring the environment as can be seen here: http://pastebin.com/5hn8vkb5
Though, it stopped in the middle with the following error message:
...
Checksum for /home/john/.cpan/sources/authors/id/A/AP/APEIRON/local-lib-1.008009.tar.gz ok
---- Unsatisfied dependencies detected during ----
---- APEIRON/local-lib-1.008009.tar.gz ----
ExtUtils::MakeMaker [build_requires]
Running make test
Make had some problems, won't test
Delayed until after prerequisites
Running make install
Make had some problems, won't install
Delayed until after prerequisites
Can't locate local/lib.pm in #INC (#INC contains:
/home/john/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
/home/john/Desktop)
at /usr/share/perl/5.14/CPAN/FirstTime.pm line 1300.
What can I do to setup the Perl environment correctly on my Ubuntu installation?
After interrupting the wizard and restarting it again, there is no error message anymore.
How can I start the wizard again so I can choose here:
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
[local::lib]
You're missing local::lib, which is what you told CPAN shell to do.
You can install it like so:
sudo apt-get install liblocal-lib-perl
You might be able to start over by rm -rf-ing your ~/.cpan directory. AT YOUR OWN RISK
However, I would recommend trying cpanminus instead of the old CPAN shell.
sudo apt-get install cpanminus
The local namespace was for your own personal modules and wouldn't be found in CPAN. This is something relatively new. At many sites, you might need CPAN modules not in the current version of Perl, or you need a newer version of a particular module. However, you don't have write access to the standard location where CPAN modules are installed.
What this is doing is installing these modules under the $HOME/perl5/lib/local directory where you'll be able to access them. You would also need to setup a PERL5LIB environment variable (usually in your startup scripts), so Perl will check this directory when locating these modules.
If you have sudo privileges, use that to install CPAN modules rather than trying this. The following will install the Foo::Bar module into the standard module directory for you (and do any configuration as necessary):
$ sudo cpan install Foo::Bar
If CPAN needs to be configured, it will do that first.
There are complete directions on doing the local::lib install for modules on MetaCPAN. They're pretty clear.
Several New OS's force (like Redhat 7) force to check presence of local::lib in the perl version, actually its a good thing this enables to users to use CPAN and add,experiment and enjoy new modules to be used with the perl without waiting for sitewide installation (like a root user). By default local::lib looks for $HOME/perl5 dir where the user's local or downloaded modules are located. If you see this problem then you have to do following
sudo su - whatever_user_owns_perl
whatever_perl_install_path/cpan install local::lib
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.