简体   繁体   English

在Perl中使用DBI时出错

[英]Error using DBI in perl

I'm unable to use DBI in my current version of perl on my Mac. 我无法在Mac上的当前Perl版本中使用DBI。 When I try to do a simple 当我尝试做一个简单的

my $database = "DBI:Pg:dbname=db;host=localhost";
my $db_user = "user";
my $db_pw = "pw";
my $dbh = DBI->connect($database, $db_user, $db_pw, {'RaiseError' => 1});

I get the following error: 我收到以下错误:

 install_driver(Pg) failed: Can't locate DBD/Pg.pm in @INC 
 Perhaps the DBD::Pg perl module hasn't been fully installed,
 or perhaps the capitalisation of 'Pg' isn't right.

I do have two versions of PERL on my machine, but I believe I successfully (using CPAN) installed DBI on the version I am using as a 我的机器上确实有两个版本的PERL,但我相信我已经成功(使用CPAN)在要用作DBL的版本上安装了DBI。

/Applications/apps/bin/perl -e "use DBI" 

does not return an error. 不返回错误。

However, I'm not positive I installed the module using CPA as it ends with this message: 但是,我不太肯定我使用CPA安装了该模块,因为它以以下消息结尾:

Running make install make test had returned bad status, won't install without force Failed during this command: TURNSTEP/DBD-Pg-2.18.1.tar.gz : make_test NO 运行make install make测试已返回错误状态,如果没有强行安装将不会安装该命令失败:TURNSTEP / DBD-Pg-2.18.1.tar.gz:make_test NO

Do I need to do something other than a 我是否需要做其他事情而不是

sudo cpan DBD:PG

if I have more than one version of Perl on my machine? 我的机器上是否有多个版本的Perl?

UPDATE: I had a mispelling and should have been doing a sudo CPAN DBI. 更新:我拼错了,应该一直在做sudo CPAN DBI。 I've since done that but I'm still getting the same error. 从那以后我就做了,但是我仍然遇到同样的错误。

I'm guessing here because you do not show the whole output of CPAN with full error messages. 我在这里猜测是因为您没有显示带有完整错误消息的CPAN的整个输出。

I suspect that the cause is like in the overwhelming majority of cases that you neglected to install the development headers for PostgreSQL. 我怀疑原因是在绝大多数情况下您都忽略了为PostgreSQL安装开发标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM