操作系統:Mac 10.12.1中,MySQL 5.7.15即使cpan告訴我DBD :: mysql已安裝,爲什麼我的Perl腳本找不到DBD/mysql.pm?
perl -e 'print $];' 5.016000
錯誤消息:
Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at ./testDBConnection.pl line 8. BEGIN failed--compilation aborted at ./testDBConnection.pl line 8.
源代碼:
#!/usr/bin/perl
#use lib '/usr/bin/cpan';
use strict;
use FileHandle;
use File::Spec;
use DBI;
use DBD::mysql;
當我運行: cpan DBD::mysql
Reading '/Users/user/.cpan/Metadata'
Database was generated on Fri, 18 Nov 2016 19:41:02 GMT
DBD::mysql is up to date (4.039).
當我運行:perldoc -lm DBI DBD::mysql
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/DBI.pm
/Users/user/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/DBD/mysql.pm
有什麼建議?
看起來像你正在使用perlbrew。查看https://perlbrew.pl/ –
嘗試直接使用perl運行腳本:'perl script.pl'。另外,將你的shebang行改爲'#!/ usr/bin/env perl'也可以解決它的問題 – stevieb
@stevieb問題在於OP告訴shell使用'/ usr/bin/perl'來執行腳本。腳本,shell和環境都在OP的控制之下。無需解決方法。 –