操作系统: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的控制之下。无需解决方法。 –