为Perl安装了JSON模块但无法加载它,无法在@INC中找到JSON.pm

时间:2016-12-14 13:17:12

标签: json perl

我使用命令

为PERL安装了JSON
sudo perl -MCPAN -e 'install JSON'

但我无法使用它,use JSON;会导致错误:

  

无法在@INC中找到JSON.pm(您可能需要安装JSON模块)
  (@INC包含:/ 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。)在   /Users/snaggs/Appsflyer/projects/build-machine-sdk/scripts/build_ios.pl   第13行。开始失败 - 编译中止   /Users/snaggs/Appsflyer/projects/build-machine-sdk/scripts/build_ios.pl   第13行。

ls -l /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/JSON/给了我:

drwxr-xr-x  3 snaggs  staff    102 Nov 29 12:53 PP
-r--r--r--  1 snaggs  staff  82532 Nov 29 12:53 PP.pm

$ perl -V给了我:

Summary of my perl5 (revision 5 version 16 subversion 0) configuration:

  Platform:
    osname=darwin, osvers=16.1.0, archname=darwin-2level
    uname='darwin snaggss-macbook-pro.local 16.1.0 darwin kernel version 16.1.0: thu oct 13 21:26:57 pdt 2016; root:xnu-3789.21.3~60release_x86_64 x86_64 '
    config_args='-de -Dprefix=/Users/snaggs/perl5/perlbrew/perls/perl-5.16.0 -Aeval:scriptdir=/Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
    optimize='-O3',
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'


Characteristics of this binary (from libperl): 
  Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_ALL
                        USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE
                        USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Locally applied patches:
    Devel::PatchPerl 1.38
  Built under darwin
  Compiled at Nov 29 2016 12:51:12
  %ENV:
    PERLBREW_BASHRC_VERSION="0.78"
    PERLBREW_HOME="/Users/snaggs/.perlbrew"
    PERLBREW_MANPATH="/Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/man"
    PERLBREW_PATH="/Users/snaggs/perl5/perlbrew/bin:/Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/bin"
    PERLBREW_PERL="perl-5.16.0"
    PERLBREW_ROOT="/Users/snaggs/perl5/perlbrew"
    PERLBREW_VERSION="0.78"
  @INC:
    /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level
    /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0
    /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level
    /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0

3 个答案:

答案 0 :(得分:4)

错误消息中@INC的路径列表意味着您正在尝试使用系统perl,但是您已经为perlbrew管理的perl版本安装了该模块。

您需要确保使用正确版本的perl运行脚本。

最可能的原因是你有一个shebang线#!/usr/bin/perl。将其更改为#!/usr/bin/env perl,以便在$PATH中搜索perl。或者,将其更改为您使用perlbrew安装的perl版本的完整路径。

答案 1 :(得分:4)

您已经为尝试使用它的perl实例安装了该模块。试试这个看看差异

perl -E'say $^X'

sudo perl -E'say $^X'

我看到你正在使用perlbrew,因此在运行命令之前切换到适当的实例应该很简单

顺便说一句,perl -MCPAN -e 'install JSON'最好写成cpan JSON

答案 2 :(得分:1)

问题在于:

  • Perl/5.18
  • perl-5.16.0

你有两个不同版本的perl在玩。我建议您需要sudo perl -MCPAN -e 'install JSON'使用您在脚本中使用的路径。 (或者将脚本更改为指向其他二进制文件)