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

vhmi4jdf  于 2023-10-24  发布在  Perl
关注(0)|答案(4)|浏览(244)

我安装了JSON for PERL,命令如下:

sudo perl -MCPAN -e 'install JSON'

但是我不能使用它,use JSON;导致错误:
无法在@INC中找到JSON.pm(您可能需要安装JSON模块)
(@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 .),
/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
j13ufse2

j13ufse21#

错误消息中@INC的路径列表表明您正在尝试使用系统perl,但您已经安装了由perlbrew管理的perl版本的模块。
你需要确保你运行的脚本是正确版本的perl。
最有可能的原因是你有一个shebang行#!/usr/bin/perl。将其更改为#!/usr/bin/env perl以搜索$PATH中的perl。或者,将其更改为perlbrew安装的perl版本的完整路径。

e3bfsja2

e3bfsja22#

您已经为不同的perl示例安装了该模块,而不是您尝试使用它的那个示例。

perl -E'say $^X'

sudo perl -E'say $^X'

我看到您正在使用perlbrew,因此在运行命令之前切换到适当的示例应该足够简单
顺便说一下,perl -MCPAN -e 'install JSON'最好写成cpan JSON

lf3rwulv

lf3rwulv3#

问题来了:

  • Perl/5.18
  • perl-5.16.0

你有两个不同版本的perl在运行。我建议你需要sudo perl -MCPAN -e 'install JSON'使用你在脚本中使用的路径。(或者改变你的脚本指向另一个二进制文件)

axkjgtzd

axkjgtzd4#

sudo cpan JSON

试试这个;它应该解决这个问题。

相关问题