DBD::Pg on Mac OS X - not found any way
سؤال
Executing a .cgi from the command-line (as the user who has access to the db), I get
install_driver(Pg) failed: Can't locate DBD/Pg.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at (eval 4) line 3. Perhaps the DBD::Pg perl module hasn't been fully installed, or perhaps the capitalisation of 'Pg' isn't right.
cpan -D DBD::Pg shows
DBD::Pg
Postgres Driver for DBI T/TU/TURNSTEP/DBD-Pg-2.19.2.tar.gz /opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/DBD/Pg.pm Installed: 2.19.2 CPAN: 2.19.2 up to date DBD::Pg Developers (DBDPG) dbd-pg@perl.org
Trying to export above path by PERL5LIB or PERLLIB has no different outcome.
The .cgi references /usr/bin/perl, which tells
This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level (with 2 registered patches, see perl -V for more detail)
I like to permanently set the module path to the one where DBD::Pg is installed (/opt/...). I wonder why that is not mentioned by the error outputs directory listing.
I installed DBD::Pg via cpanm.
I use Mac OS X Mountain Lion.
المحلول
You appear to have two different builds of Perl installed. The one with which you are running your script is different than the one used to run cpan
. To install DBD::Pg with the correct Perl, use
perl -MCPAN -e'install DBD::Pg'
Replace perl
with the path to the Perl used to run your script, if necessary.
نصائح أخرى
/opt/... indicates a "3rd party" Perl. "which perl", "which cpan" show that the 3rd party Perl is used by running capn. That's MacPort's. As I installed with cpan and cpanm, the 3rd party Perl got updated. Executing as a different user and the /usr/bin/perl shebang instruct the Mac OS X perl to be used. As I must use the shebang and the different user, I must use Mac OS X perl. Explicitly adding the module by /usr/bin/cpan DBD::Pg installs the module to the Mac OS X Perl. Now my .cgi runs. Alternatives to switch to the 3rd party Perl are changing the shebang to ".../env perl" or using aliases in the file system.