在 perl 中使用 DBI 时出错

发布于 2024-12-21 05:36:11 字数 920 浏览 0 评论 0原文

我无法在 Mac 上当前版本的 perl 中使用 DBI。当我尝试执行简单操作时,

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});

出现以下错误:

 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.

我的计算机上确实有两个版本的 PERL,但我相信我已成功(使用 CPAN)在我正在使用的版本上安装了 DBI,

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

不会返回错误。

但是,我不确定我是否使用 CPA 安装了该模块,因为它以以下消息结尾:

正在运行 make install make test 返回了错误状态,不强制安装将无法安装 在此命令期间失败: TURNSTEP/DBD-Pg-2.18.1.tar.gz : make_test NO

我是否需要执行除 a 之外的其他操作

sudo cpan DBD:PG

如果我的机器上有多个版本的 Perl,

?更新:我拼写错误,应该执行 sudo CPAN DBI。我已经这样做了,但仍然遇到同样的错误。

I'm unable to use DBI in my current version of perl on my Mac. 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

/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:

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

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?

UPDATE: I had a mispelling and should have been doing a sudo CPAN DBI. I've since done that but I'm still getting the same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-12-28 05:36:11

我在这里猜测是因为您没有显示 CPAN 的整个输出以及完整的错误消息。

我怀疑绝大多数情况下的原因是您忽略了安装 PostgreSQL 的开发头文件。

I'm guessing here because you do not show the whole output of CPAN with full error messages.

I suspect that the cause is like in the overwhelming majority of cases that you neglected to install the development headers for PostgreSQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文