Can't locate DBI.pm

时间秒杀一切 提交于 2019-12-04 10:02:48

问题


I'm trying to launch this script:

#!/usr/bin/perl 

use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:host=lonlin2;sid=TIMFX1AD;port=1524','xbsesdbo','xbsesdbo123' )  || die ( $DBI::errstr . "\n" );

my $query= "SELECT * FROM product_elements WHERE element_id = 1001";
my $queryHandler= $dbh->prepare($query);

my $result= $queryHandler->execute();


open(fileHandler,"> note.txt");

print fileHandler "Risultato query: $result\n";

my $e= $dbh->disconnect();
close(fileHandler);

When I launch this script I receive this error:

Can't locate DBI.pm in @INC (@INC contains: /opt/perl_32/lib/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/5.8.3 /opt/perl_32/lib/site_perl/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/site_perl/5.8.3 /opt/perl_32/lib/site_perl /opt/perl_32/lib/vendor_perl/5.8.3/IA64.ARCHREV_0-thread-multi /opt/perl_32/lib/vendor_perl/5.8.3 /opt/perl_32/lib/vendor_perl .) at ./prova.pl line 3.

I've got all installed!! DBI.pm is installed !!


回答1:


If you have root, type in console (Debian/Ubuntu):

sudo apt-get install libdbi-perl



回答2:


If you don't have active perl (and hence don't have ppm), you can also get DBI like this:

perl -MCPAN -e 'install DBI'

You may need to install drivers for Postgres like this:

perl -MCPAN -e 'install DBD::Pg'



回答3:


DBI isn't in your @INC path, which tells perl where to look for custom modules. This is probably because you've installed them using the cpan tool as a non-root user, which won't have write access to the default include paths.

You will need to locate DBI.pm and other packages, and move them into your @INC path.

Alternatively, find the packages you've installed and add the install path into your library path, for one time use:

PERL5LIB=/path/to/modules perl yourscript.pl

And for a more permanent solution, add this to ~/.bashrc:

export PERL5LIB=/path/to/modules



回答4:


For redhat/centos users:

sudo yum -y install perl-DBI


来源:https://stackoverflow.com/questions/20568836/cant-locate-dbi-pm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!