How to install JSON.pm perl module on OSX

2019-04-19 23:10发布

问题:

I am trying to use the po2json parser/converter from the JS gettext library (http://jsgettext.berlios.de/), but when I try to convert I get this error:

Can't locate JSON.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ./po2json line 23.
BEGIN failed--compilation aborted at ./po2json line 23.

As far as I understand I am missing a perl module, namely JSON.pm, an I think it's this one: http://cpansearch.perl.org/src/MAKAMAKA/JSON-2.53/lib/JSON.pm

Now, how do I install it on OSX? I am using Mountain Lion.

I tried to do cpan install JSON, but it doesn't work, I get the following error:

Writing Makefile for JSON
  MAKAMAKA/JSON-2.53.tar.gz
  make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
  Can't test without successful make
Running make install
  Make had returned bad status, install seems impossible

回答1:

The output said that make didn't return success. Probably due to some dependency. Try using cpanm http://search.cpan.org/~miyagawa/App-cpanminus-1.5017/bin/cpanm, it's really hassle free and bootstrapped quite well (no need to install other stuff).

Install using this:

curl -L http://cpanmin.us | perl - --sudo App::cpanminus



回答2:

Use homebrew to install cpanm:

brew install cpanm

Then you can install JSON with

sudo cpanm install JSON



回答3:

cpan install JSON Having the JSON in all caps made it work for me.



回答4:

I know this is an old topic, but wanted to share my solution after finding that I needed JSON when trying to use zap2xml (perl based). I was getting the error: "Can't locate JSON.pm in @INC..." after installing perl via Homebrew.

This is how I installed JSON via Homebrew. I will also include the steps required to install Homebrew (for those who would like to know). ;)

Prerequisites:

Install Xcode from the App Store (Download):

https://itunes.apple.com/us/app/xcode/id497799835

Install Command Line Tools for Xcode (Run in Terminal):

xcode-select --install

Install Homebrew (Run in Terminal):

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update Homebrew (Run in Terminal):

brew update

brew upgrade

brew doctor (correct issues found by brew doctor. Instructions will be given by The Doctor. :P)

Install cpanminus (Run in Terminal):

brew install cpanm

Check perl (Run in Terminal):

which perl

perl -V (with a capital -V)

Check/Install JSON module (Run in Terminal):

sudo cpanm -v JSON

DONE.



回答5:

Following worked for me:
Run on terminal:
sudo perl -MCPAN -e shell

you should get the cpan shell prompt and run below commond at cpan shell:

cpan[1]> install JSON

Regards,
Anand Choubey



回答6:

this way is OK, Follows the Command:sudo apt-get install libjson-perl