简体   繁体   中英

Installed JSON module for Perl but cannot load it, Can't locate JSON.pm in @INC

I installed JSON for PERL with command:

sudo perl -MCPAN -e 'install JSON'

but I cannot use it, use JSON; causes to error:

Can't locate JSON.pm in @INC (you may need to install the JSON 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
/Users/snaggs/Appsflyer/projects/build-machine-sdk/scripts/build_ios.pl line 13. BEGIN failed--compilation aborted at /Users/snaggs/Appsflyer/projects/build-machine-sdk/scripts/build_ios.pl line 13.

ls -l /Users/snaggs/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/JSON/ gives me:

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 gives me:

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

The list of paths for @INC in the error message implies that you are trying to use the system perl, but you have installed the module for a version of perl managed by perlbrew.

You need to make sure that you are running your script with the correct version of perl.

The most likely reason for this is that you have a shebang line #!/usr/bin/perl . Change it to #!/usr/bin/env perl to search the $PATH for perl. Alternatively, change it to the full path to the version of perl you installed with perlbrew.

You have installed the module for a different instance of perl from the one where you are trying to use it. Try this to see the difference

perl -E'say $^X'

and

sudo perl -E'say $^X'

I see that you are using perlbrew , so it should be simple enough to switch to the appropriate instance before you run your command

By the way, perl -MCPAN -e 'install JSON' is better written as cpan JSON

Here's the problem:

  • Perl/5.18
  • perl-5.16.0

You've got two different versions of perl in play. I would suggest that you need to sudo perl -MCPAN -e 'install JSON' using the path to the one you're using in your script. (Or change your script to point to the other binary)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM