Though there are many queries flowing around asking the same question. But here the error is thrown by apache instead of Perl.
I am trying to create an XML Response for the client on Mac OS X Mavericks and have written the perl script as follows:
#!/usr/bin/perl -wT
use lib '/opt/local/lib/perl5/site_perl/5.16.1/Geo';
use strict;
use CGI;
use Geo::Gpx;
open (FH, "/tmp/temp/file.txt") or print ("Unable to Open File");
my $gpx = Geo::Gpx->new;
my $cgi = CGI->new;
print $cgi->header(-type=>"text/gpx",-status=>"200 OK");
my $lon;
my #arr = <FH>;
foreach(#arr){
my %waypoints;
my $var = $_;
my #lat = split(/\s+/,$var);
##waypoints=split(/\s+/,$_);
$waypoints{$lat[0]}=$lat[1];
$waypoints{$lat[2]}=$lat[3];
$gpx->add_waypoint(\%waypoints);
}
my $xml = $gpx->xml;
print $xml;
open FILE, ">/tmp/temp/xmlfile.xml" or die $!;
print FILE $xml;
close (FILE);
close(FH);
For the apache to find the actual path of the Gpx.pm, I have used 'use lib' to show it the real path of the file.
Although this script is working perfectly on command line, my apache server is throwing the following error:
[Tue Nov 26 18:34:51 2013] [error] [client 127.0.0.1] Can't locate Geo/Gpx.pm in #INC
(#INC contains: /opt/local/lib/perl5/site_perl/5.16.1/Geo /Library/Perl/5.16/darwin-thread-multi-2level
/Library/Perl/5.16 /Network/Library/Perl/5.16/darwin-thread-multi-2level /Network/Library/Perl/5.16
/Library/Perl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16
/System/Library/Perl/Extras/5.16/darwin-thread-multi-2level /System/Library/Perl/Extras/5.16 .) at /Users/Rachit/Sites/temp.pl line 7.
[Tue Nov 26 18:34:51 2013] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at /Users/Rachit/Sites/temp.pl line 7.
I have used macports and have found searching through the Web that Mavericks has got perl 5.16 preinstalled. So apache may be using that and perl is using the macport installed libraries.
On checking the paths mentioned by apache error_log file as I posted above, I have copied Gpx.pm in one of the libraries installed in Geo Folder but still not getting it resolved.
On running 'which perl' The result
/opt/local/bin/perl
And 'which cpan' is giving
/opt/local/bin/cpan
Kindly fix this issue as I am not able to move forward because of this. And I am not so familiar with apache.
/opt/local/lib/perl5/site_perl/5.16.1/Geo should be /opt/local/lib/perl5/site_perl/5.16.1/ as it will append the complete module name (replacing :: with /) to each path to find the files.
Related
Context
Here is a perl test script, in which I wanted to see how you can use a specific event loop with AnyEvent :
# file test.pl :
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Impl::EV;
my $cv = AnyEvent->condvar;
my $wait_one_and_a_half_seconds = AnyEvent->timer (
after => 0.5, # after how many seconds to invoke the cb?
cb => sub { # the callback to invoke
print ("Hello from callback\n");
$cv->send;
},
);
# now wait till our time has come
$cv->recv;
Problem
Here is the error I get when running the above code :
$ perl test.pl
Can't locate EV.pm in #INC (you may need to install the EV module) (#INC
contains: /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 /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm
line 28.
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm line 28.
Compilation failed in require at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.
Yet I installed the AnyEvent package using cpanm, and the AnyEvent/Impl/EV.pm file is present in one of the #INC path :
$ ls /usr/local/lib/perl/5.18.2/AnyEvent/Impl/
Cocoa.pm Event.pm FLTK.pm IOAsync.pm Perl.pm Qt.pm UV.pm
EventLib.pm EV.pm Glib.pm Irssi.pm POE.pm Tk.pm
Question
How do I fix this ?
Extra remark
The error message says it is looking for EV.pm, but I would have expected AnyEvent/Impl/EV.pm.
How come the use AnyEvent::Impl::EV; I wrote got turned into perl is looking for EV.pm at runtime ?
Just tried to reproduce this with cpan install AnyEvent and can confirm I get the same error.
Line 28 of 'EV.pm' is use EV 4.00;. Your use EV; is a bit of a red herring - that's not the source of the error. This module explicitly includes a 'use' line (which frankly is a bit wierd, it's 'using' itself it seems?)
I don't think that's ever going to work, unless the #INC path is changed - I can only assume that the loading of this module is handled elsewhere, without deconstructing source code.
Referencing the man page - this module gets loaded automatically as required. So you probably don't need to use it in the first place.
Edit: Just compared perl versions. Perl 5.8.5 shows the same behaviour. My 5.20.1 install doesn't.
I'm not sure upgrading perl is necessarily the right step, but it might be worth trying? I'll try and figure out why 5.20.1 works though. It's got to be something to do with handling of #INC.
Edit:
"The handling of return values of #INC filters (subroutines returned by subroutines in #INC) has been fixed in various ways. Previously tied variables were mishandled, and setting $_ to a reference or typeglob could result in crashes."
http://perldoc.perl.org/perl5200delta.html
I think that might be what the problem is.
You're certainly not alone in having this:
http://www.cpantesters.org/cpan/report/d5939816-a510-11e0-bd04-22322d9f2468
From:
http://cpansearch.perl.org/src/MLEHMANN/AnyEvent-7.08/Changes
5.29 Sun Dec 5 10:49:21 CET 2010
- convert EV backend to EV 4.00 API (so better upgrade EV too).
The error message was actually a very correct and forward pointer to what should be done : there is an EV package which needs to be installed separately :
$ sudo cpanm EV
--> Working on EV
Fetching http://www.cpan.org/authors/id/M/ML/MLEHMANN/EV-4.18.tar.gz ... OK
Configuring EV-4.18 ... OK
Building and testing EV-4.18 ... OK
Successfully installed EV-4.18
1 distribution installed
After that, everything works :
$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use EV;
my $wait_one_and_a_half_seconds = AnyEvent->timer (
after => 0.5, # after how many seconds to invoke the cb?
cb => sub { # the callback to invoke
print ("Hello from callback\n");
},
);
# now wait till our time has come
EV::run();
$ perl test.pl
Hello from callback
I am trying to use wikiprep (https://github.com/avian2/wikiprep) to parse wikipedia dump (in Feb 2014) and generate a XXX.hgw.xml file from the dump.
I followed the usage on Github site above: installed all Perl modules as prerequisites; Build and install wikiprep successfully (wikiprep program appeared in perl5/bin directory). When I execute wikiprep, it says:
Use of the encoding pragma is deprecated at /home/tutran/perl5/bin/wikiprep line 32.
Use of the encoding pragma is deprecated at /home/tutran/perl5/lib/perl5/Wikiprep/languages.pm line 7.
syntax error at /home/tutran/perl5/lib/perl5/Wikiprep/Disambig.pm line 9, near "->import qw/ extractWikiLinks /"
Compilation failed in require at /home/tutran/perl5/bin/wikiprep line 52.
BEGIN failed--compilation aborted at /home/tutran/perl5/bin/wikiprep line 52.
This the line 9:
Wikiprep::Link->import qw/ extractWikiLinks /;
Expected output: options I can use with wikiprep. I also cannot make test for the program. I installed it on Ubuntu 14.04 LTS. My Perl version is 5.18.02.
I don't know anything about perl language so I can't do anything with the "syntax error" here!
You may need enable ut8 in your script. PLace this two lines before you start using this module:
use utf8;
use open qw( :encoding(cp866) :std );
In /usr/local/bin/ wikiprep change line 135 i'e (Wikiprep::Templates->import qw( %templates includeTemplates );) to :
Wikiprep::Templates->import(qw( %templates includeTemplates ));
and
in file
/usr/local/share/perl/5.18.2/Wikiprep/Disambig.pm
change
Wikiprep::Link->import qw/ extractWikiLinks /; to
Wikiprep::Link->import(qw/ extractWikiLinks /);
PROBLEM: In the process of trying to install gitstat on a Windows7 machine I broke my xampp Apache installation. Now I can't get gitstat or apache to work.
APACHE ERROR:
[error] Can't load Perl file: C:/xampp/apache/conf/extra/startup.pl for server localhost:80, exiting...`
Other people have reported this issue being caused by the PERL5LIB environment variable, but that variable does not exist on my machine.
WHAT I DID / GITSTAT ERROR:
I needed the SOAP::Lite module installed so I followed the windows guide here: http://soaplite.com/install.html
As far as I could tell I installed the module successfully, console output below
cpan[1]> install SOAP::Lite
CPAN: Storable loaded ok (v2.21)
Going to read '\xampp\perl\bin\.cpan\Metadata'
Database was generated on Wed, 27 Jun 2012 02:47:03 GMT
SOAP::Lite is up to date (0.714).
I saw a SOAP directory in perl/site/lib which (to me) means that the module should be available. When I look in my perllocal.pod file SOAP:Lite is in there.
Part of the gitstat installation instructions say to copy the Lite.pm file from perl/site/lib/SOAP into gitstat\gstat_pl\lib
However, when I try to perform step nine of gitstat installation (perl gitstat.pl HEAD) I get the following:
C:\xampp\htdocs\gitstat\gstat_pl>perl gitstat.pl HEAD
Supported versions:
BEGIN failed--compilation aborted at C:/xampp/perl/site/lib/SOAP/Lite.pm line 34
86.
Compilation failed in require at C:/xampp/perl/site/lib/SOAP/Constants.pm line 1
3.
BEGIN failed--compilation aborted at C:/xampp/perl/site/lib/SOAP/Constants.pm li
ne 13.
Compilation failed in require at lib/Lite.pm line 3444.
BEGIN failed--compilation aborted at lib/Lite.pm line 3444.
Compilation failed in require at gitstat.pl line 30.
If I don't copy the file from perl/site/lib/SOAP then I get
C:\xampp\htdocs\gitstat\gstat_pl>perl gitstat.pl HEAD
Can't locate lib/Lite.pm in #INC (#INC contains: C:/xampp/perl/lib C:/xampp/perl
/site/lib .) at gitstat.pl line 30.
I don't understand why CPAN didn't install the Lite.pm module in the #INC path or why the compilation might fail when the module is available, or most importantly why my Apache install is broken. Also I'm very new to Perl and CPAN and my understanding of Apache is primitive so simpler explanations would be greatly appreciated.
I have a code
use Tie::File::AsHash;
tie %sets, 'Tie::File::AsHash', '.\\main\\old_names.txt', split => '\+' or die "Problem trying to %hash: $!";
and I get the error:
Can't locate Tie/File/AsHash.pm in #INC <#INC contains: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .> at C:\Users\user\Desktop\test.pl line 97 (which is the second line I posted)
BEGIN failed--compilation aborted at line 97.
That usually indicates that the module isn't installed. One normally installs a module as follows:
cpan Tie::File::AsHash
My hosting provider has recently upgraded their servers and I am having lots of problems with imagemagick scripts in perl. My script worked perfectly on the old server but fail on the new one so I have gone back to basics to try and sort out what is going wrong.
The server reports the imagemagick as:
Version: ImageMagick 6.7.2-2 2011-10-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
and the perl module Image::Magick is version 6.72
The following script is saved on my server:
#!/usr/bin/perl
use CGI::Carp qw( fatalsToBrowser );
use Image::Magick;
my $image = Image::Magick->new;
$x = $image -> Set(size=>"200x200");
warn "$x" if "$x";
$x = $image -> ReadImage("canvas:black");
warn "$x" if "$x";
$x = $image -> Draw (
stroke => "red",
primitive => "line",
points => "20,20 180,180");
warn "$x" if "$x";
print "Content-type: image/gif\n\n";
binmode STDOUT;
$image -> write ("gif:-");
This fails with the following errors:
[Sun Oct 23 11:02:32 2011] imtest.pl: Exception 420: no decode delegate for this image format `lack' # error/constitute.c/ReadImage/532 at www/11/cgi-bin/imtest.pl line 12.
[Sun Oct 23 11:02:32 2011] imtest.pl: Exception 410: no images defined `Draw' # error/Magick.xs/XS_Image__Magick_Mogrify/7394 at www/11/cgi-bin/imtest.pl line 18.
If I change ReadImage("canvas:black") to ReadImage("xc:black") then the script runs continuously with no output.
My webhost has been great in trying to find a solution but I need to know if I am doing something wrong here, or if there is an installation problem with imagemagick.
Please note I realise the above can be done with other simpler modules but this is just a simple example to determine if the problem is imagemagick or my code!
Thanks for your help.
Regards,
Stu
I received similar errors in winxp command line mode with version 6.3.7 of ImageMagick.
I changed the first few lines to this and it worked:
my $image = Image::Magick->new(size=>"200x200");
die "Image::Magick->new failed" unless $image;
my $x = $image->Read("xc:black");
warn "$x" if "$x";