Can't locate Connection.pm in @INC (@INC contains: /usr/local/lib/perl/5.14.2 /etc/perl /usr/local/share/perl/5.14.2 …) at ./select.cgi at line
-
01-07-2021 - |
Вопрос
I am trying my hands for the first time in -> Apache - Perl (CGI) on Ubuntu.
The Apache server is working fine in the folder /var/www
for the default index.html
file. But since I want to run a CGI script, I also installed (just in case) DBI, as suggested by some forums. I set the permissions for complete access to my cgi-bin
folder in which the select.cgi
script resides. I tried tweaking the select.cgi
script multiple times redirecting the library to the Perl library, but to no avail. I modified the httpd.conf
file and set the directory path to the select.cgi
folder. That didn't work. I also defined ScriptAlias
, and set it to the working directory. That didn't work either.
Does anyone have any helpful pointers. Thanks.
Решение
In a comment, you gave information that contradicts what you gave originally. The latter information appears to be more reliable, so I'll use it.
I believe you said the path to the module is
/usr/lib/perl5/vendor_perl/5.8.5/foo/bar/Connection.pm
and that the error message you got (with line breaks added) is:
Can't locate foo/bar/Connection.pm in @INC (@INC contains:
/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
.
/usr/lib/perl5/vendor_perl/5.8.5/foo/bar/
) at ...
You did something like
use foo::bar::Connection;
or
require "foo/bar/Connection.pm";
Perl looked for
/etc/perl/foo/bar/Connection.pm
/usr/local/lib/perl/5.14.2/foo/bar/Connection.pm
- ...
/usr/lib/perl5/vendor_perl/5.8.5/foo/bar/foo/bar/Connection.pm
But none of those are
/usr/lib/perl5/vendor_perl/5.8.5/foo/bar/Connection.pm
It's simple to fix. Add the following to your script:
use lib '/usr/lib/perl5/vendor_perl/5.8.5';
The other possible fix is to use
use Connection;
instead of
use foo::bar::Connection;
Which fix is the correct fix depends on what that package
line in side the module looks like. If you find package foo::bar::Connection;
, you need to modify @INC
(as shown with use lib, for example). If you find
package Connection;, you need to change the
use` directive.
Другие советы
This is not exact solution that you want but the overall idea is like below.
How to resolve Cant locate xxxx.pm in @INC path
problem
By default perl looks for modules in the standard library path and the current directory. Sometimes you need to use some modules that are installed in non standard locations; there are several ways to deal with this situation:
To check whether your module is in @INC
path use.
Example:
perl -e 'use SOAP::Lite;'
perl -e 'use Error;'
If you run these commands on a system that has SOAP::Lite
and Error
installed, Perl will simply return from these commands without printing any output.
To check current standard library path use:
perl -le 'print foreach @INC'
If you have the administrative privileges, then best solution is to install the module in any of the system defined library path.
Set the environment variable PERL5LIB
Perl will look for modules in the directories specified in PERL5LIB
environment variable before looking in the standard library and current directory.
So you can set this variable to locate your modules.
Example:
# For unix like systems
PERL5LIB=/home/path/lib:/usr/another/path/lib; export PERL5LIB
Note: separate the directories with colons on unix and with a semicolon on Windows.
IF you are running your code from command line then use -I
parameter. The syntax should be something like.
perl -I /home/path/lib -I /usr/another/lib script.pl
And you can also Add the library path in your script
The command for including the path in your script is: use lib path
.
Example:
#!/usr/bin/perl
use lib "/home/path/lib";
use lib "/usr/another/lib";
use MyCustomModule;