When I run my perl program, i get the error, i have tried googling it, but i could not find a definitive easy to solve answer
C:\Users\mte>C:\Users\mte\Desktop\org11.pl
Can't locate org2.pm in #INC (you may need to install the org2 module) (#INC con
tains: C:/Perl64/site/lib C:/Perl64/lib .) at C:\Users\mte\Desktop\org11.pl line
2.
BEGIN failed--compilation aborted at C:\Users\mte\Desktop\org11.pl line 2.
the beginning of my code looks like this
use warnings;
use org22;
Either your perl path is incorrect/lacking, or the org22 module is not installed. Take a look at this post for more information on constructing an #INC. Make sure that the org22 module is installed (and if it isn't, that's likely the cause of this error.)
Edit:
If your module is not in #INC (the standard perl include path), and assuming that your module (for example) is located at C:\Some\Path\MyModule.pm, then:
use lib 'C:\Some\Path';
use MyModule;
# Rest of your code
You also may consider using a shebang line as the 1st line in your script:
#!/bin/perl
or
#!/usr/bin/env perl
This will help ensure a consistent experience based on which perl interpreter you are using, given updates, installations of other programs, etc.
Related
I have a module Term:TermKey, which is in a file TermKey.pm. I don't want to install it into my perl; I want it to be referenced locally so that the script can be moved to other machines without messing about with each perl installation. How do I do this? None of the recommendations I have seen online works. I always get some form of:
Can't locate loadable object for module Term::TermKey in #INC (#INC contains: /home/fritz/multi.kodis/Term /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at test.pl line 6.
Compilation failed in require at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.
To test this. I placed copies of TermKey.pm in all of:
./TermKey.pm
./Term/TermKey.pm
./Term/Term/TermKey.pm
(just as a test)
Yet it doesn't work for any of:
use lib '';
use Term::TermKey;
use lib '.';
use Term::TermKey;
use lib './';
use Term::TermKey;
use lib './Term';
use Term::TermKey;
use lib './Term/';
use Term::TermKey;
use lib '/home/[user]/[project]'
use Term::TermKey;
use lib '/home/[user]/[project]/Term'
use Term::TermKey;
use FindBin;
use lib "$FindBin::RealBin";
use Term::TermKey;
What the heck? This should be easy, what am I missing?
"Can't locate loadable object for module" does not mean that Perl can't find Term/TermKey.pm. It means that it can't find Term/TermKey.so (or whatever shared libraries are called on your platform).
Term::TermKey is not a pure-Perl module. Instead, it includes XS code, which needs to be compiled into C and then into a shared library. Also, that library links to libtermkey, which must also be installed on your system.
This makes it much harder to move the module from system to system. An XS module compiled for Perl 5.18.2 won't work with 5.20.0; it has to be recompiled. You can upgrade minor releases (like from 5.18.0 to 5.18.2) without having to recompile, although going the other direction (from 5.18.2 to 5.18.0) isn't guaranteed to work.
So, you might be able to get this to work if all the machines are running the same version of Perl on the same OS with the same libraries installed. The easiest way (if it works at all) would be to install cpanm and local::lib and do something like:
cpanm --local-lib some-dir Term::TermKey
Then you could copy some-dir to another machine (with the caveats listed above). It isn't necessary to install local::lib on the other machines; you can just
use lib 'some-dir/lib/perl5';
I would like to deploy my Perl application to several remote servers. My perl application consists of one big program, using non-core modules : Path::Iterator::Rule, XML::Writer, and two home-made modules.
I would like to be able to deploy my application on a remote server whithout having to copy one by one all of the modules my program uses, with all their dependencies.
I had a look at PAR, which could help with what I'd like to do.
I need to create an archive ("modules.par") where I put my homemade modules, and I add Path::Iterator::Rule, XML::Writer modules ? But how can I be sure that all the dependencies of those modules are correctly added in my archive ?
I've understood that I need to do something like this in my main application :
use PAR;
use lib "modules.par";
use Path::Iterator::Rule;
use XML::Writer;
use HomemadeModule1;
use HomemadeModule2;
Sorry for the confusion, I'm really lost with all those module dependencies, ..
Edit :
So I've tried using cpanm -L extlib to create a directory with all my libraries, but I can't use cpanm on my system.
Now I'm trying to use PAR, I've created a file called "sources.par" in which all of my modules are contained, I used the following command :
pp -p myperlprogram.pl
This created the "sources.par", that I should be able to use in my program using this :
use PAR;
use lib "sources.par";
use XML::Writer;
use ..
But I still get the following message :
Can't locate XML/Writer.pm in #INC (#INC contains: sources.par CODE(0x10c0cc) /app/pro
dexpl/gld/LOA /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/
perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/s
ite_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/
5.8.4 /usr/perl5/vendor_perl . CODE(0x10c1e0)) at /app/prodexpl/gld/LOA/AnalyseF
ichier.pm line 7.
BEGIN failed--compilation aborted at /app/prodexpl/gld/LOA/AnalyseFichier.pm lin
e 7.
Compilation failed in require at /app/prodexpl/gld/LOA/loganalysis.pl line 9.
BEGIN failed--compilation aborted at /app/prodexpl/gld/LOA/loganalysis.pl line 9
.
Any ideas what I could do ? You can see that #INC contains my sources.par file..
Create a package using either Module::Build or Module::Build::Tiny, and then just install the package on these remote machines. That way you can just specify what the dependencies are, and cpanm can install them as well.
I'm trying to get the resolution,width,height of the images in the specific file.
I have the following code.
#use strict;
use Image::Info qw(image_info dim);
use File::List;
#perl2exe_include Image::Info::JPEG;
#perl2exe_include PerlIO;
my $file = <ImageFilePath>;
my $info = image_info($file);
my $res = $info->{resolution};
print "$$res[0]\n";
I have the Perl Version 5.16.3
I get the following error:
Can't locate Image/Info.pm in #INC (#INC contains: c:\program files\Perl\lib c:/program files/Perl/site/lib c:/program files/Perl/lib .) at Img_Res.pl line 3.
BEGIN failed--compilation aborted at Img_Res.pl line 3.
Can anyone give me the solution to this?
From the code part of question I am concluding that you are trying to create an executable using Perl2EXE, because you are using the line
#perl2exe_include Image::Info::JPEG;
and also assuming that you are running command
perl2exe c:\somepath\somescript.pl -o somescript.exe
The answer from #James Green is correct to an extent, however its incomplete (as in fails to explain his second bullet point).
You need to install "Image::Info" and any other modules that you are using (Use the answer from #James Green).
After installation, Open to windows explorer and locate the module that you just installed,
It will normally be in the following folders
"PERL_PATH\perl\lib"
"PERL_PATH\perl\site\lib"
"PERL_PATH\perl\vendor\lib"
Once you locate the module is installed in the one of the 3 locations above. Navigate to the location where Perl2EXE is installed.
PERL2EXE_PATH\perl2exe-XX.xx-Win\
Locate the folder with the current version of perl you are using. In your case the folder name should be
Win32-5.16.3 or Win64-5.16.3
Open the folder and locate the .conf file.
Edit the line with header libdir.
libdir=perl-Win32/site/lib;perl-Win32/lib;perl-Win32/vendor/lib;.
Ensure all the perl/lib directories are included in the search path.
Save it and rerun your command. This should work.
Sometimes even after all this the perl2exe command fails, this is due to the limitation of the program being able to decipher the qw command.
So to avoid this directly call the module (ex: use Module::Name;) in your code instead of using the qw.
You need to ensure you've done two things:
install the Image::Info module
make sure #INC includes the path to wherever you installed the module
I see you're on Windows, which means you're likely using either Strawberry Perl, or ActiveState's Perl. If you're using Strawberry Perl you should have some success following the directions on http://www.cpan.org/modules/INSTALL.html -- I believe ActiveState has its own built-in package manager, ppm, and to get started with that you'll want to look here: http://www.activestate.com/activeperl/ppm-perl-modules
I need to run a perl script to gather system information that will be deployed and executed on different unix servers.
Right now I am writing it and testing it, and I'm receiving this error.
Can't locate XML/DOM.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
test.pl line 7. BEGIN failed--compilation aborted at test.pl line 7.
So I am simply using XML::DOM which should be part of Perl but it isn't for this version on this particular server which is 5.10.1.
Anyways, is there a way I can create and design my script and package modules into it while keeping the .pl extension, which is the requirement for this script?
If the modules don't require compiled libraries, you can include them by copying the text out of the module into your .pl file. That's a horrible hack but it should work.
Perl modules should contain a package statement that gives them their name. When you get to your main program section you'll need a package main; statement of your own.
You can put the modules in any directory, and then include this directory to be included in the search for modules via the lib pragma. Be aware that a module Foo::Bar has to be in the file MY-ROOT/Foo/Bar.pm and may not be in MY-ROOT/Bar.pm, where MY-ROOT is your module directory.
use lib 'MY-ROOT';
use Foo::Bar;
However, this only works for pure-Perl modules, and doesn't support XS.
In lieu of using the lib pragma as amon suggests, consider installing perlbrew and cpanminus which is designed to work hand-in-hand to add and/or update modules.
perlbrew is designed to be leveraged by specifying #!/usr/bin/env perl as the interpreter line in your Perl scripts while adding a line like source ~/perl5/perlbrew/etc/bashrc to your ${HOME}/.bash_profile to locate the local version of Perl you want.
I am currently trying to create/generate a CSV file using one of three classes:
use Class::CSV;
use Text::CSV;
use Text::CSV_XS;
Though when I try and run it, to check my code I come up with the same error message:
Can't locate Class/CSV.pm in #INC (#INC contains: C:/Per/site/lib C:/Perl/lib .) at C:\Users\<DIRECTORY> - <DIRECTORY>.file.pl line1
I have tried searching for the files though I haven't had any luck. Has anyone else come up against this problem? I have looking in the Directory and the CSV.pm file does exists.
Assuming that Class::CSV is installed on your system, your library search path is incomplete. (Your error message lists C:/Per/site/lib as a search lib, which looks like a typo for C:/Perl/site/lib, which you might want to look into.)
You need to locate the correct CSV.pm file where the library is located. For example, if it's found in:
C:/Perl/lib/foo/Class/CSV.pm
Then you have one of the following options.
Modify the environment for Perl or the invocation so that this is set (assuming my Windows skill haven't expired completely, someone feel free to edit and correct if I get the syntax wrong):
PERL5LIB=%PERL5LIB%;C:/Perl/lib/foo
You can use the -I option to perl to add the path:
perl -IC:/Perl/lib/foo my-app.pl
You can use the use lib command in the program itself to add the search path:
use lib 'C:/Perl/lib/foo';
use Class::CSV;
# etc.
You probably don't have these modules installed.
run this in your shell
perl -MCPAN -e shell
then run
install Class::CSV
I'm assuming that you found these classes on CPAN
You can simply run the following command
perl -MCPAN -e 'install Class::CSV'
to run
install Class::CSV in CPAN shell.