Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Can't locate JSON.pm in @INC

by brewzzer (Novice)
on Feb 13, 2014 at 19:50 UTC ( [id://1074885]=perlquestion: print w/replies, xml ) Need Help??

brewzzer has asked for the wisdom of the Perl Monks concerning the following question:

Trying to run a perl script that uses the perl module JSON. I installed the module, but when I run the script, I get: "Can't locate JSON.pm in @INC"

When I tried re-installing the module (cpanm JSON) I get: "JSON is up to date. (2.90)"

Can someone offer some hints? I'm a compete newbie on UNIX and installing modules, so please talk in baby terms.

I understand that modules need to be in @INC, but I don't understand why it is not so automatically after a successsful installation, or how to make it so.

The line in the perl script calling JSON is this: use JSON;

If JSON.pm is not in @INC, can I specific a path in the line above to make it accessible to the script? If so, how would I go about finding that path, and what would be the format of the line in the perl script?

Thanks!

UPDATE: Guys -- Thank you for your great help. With your advice, I was able to quickly understand and solve the problem, and gain some knowledge that will help me in the future. You guys are awesome! Thanks again.

Replies are listed 'Best First'.
Re: Can't locate JSON.pm in @INC
by BaldManTom (Friar) on Feb 14, 2014 at 01:00 UTC

    Hi brewzzer,

    How are you calling your script? Are you calling it using something akin to:

    perl script.pl

    or have you set the permissions on the script to be executable and then just called:

    script.pl

    If the latter, look a the first line of your script, the "she-bang line". It should look something like:

    #! /usr/bin/perl

    Now execute the following from a command prompt:

    which perl

    I'd guess that will show something different than you have in your script, which means you're trying to run with a perl other than the one where JSON.pm is installed. Try updating that first line to match the location of your perl executable located by using the which command.

    Alternatively, you could change that first line to:

    #! /usr/bin/env perl

    That should pick up the same perl for which JSON.pm is installed.

    Good luck!

    -BMT

Re: Can't locate JSON.pm in @INC
by Anonymous Monk on Feb 13, 2014 at 20:21 UTC
    look at the log, turn on verbosity  cpanm -v JSON , check which cpanm you're calling and which perl its calling (shebang)
Re: Can't locate JSON.pm in @INC
by sundialsvc4 (Abbot) on Feb 14, 2014 at 01:56 UTC

    First, do this:

    perl -V
    with a capital -V ...

    This will give you, among a great many other things, a complete list of all the places that Perl will look for anything, and the sequence in which it will look for them.   (Within a running Perl program, this is accessible as the array-variable, @INC ...)

    If Perl cannot find a module, yet cpan can, it simply means that the two are not looking in the same places.   (And, by the way, this is by design ...)

    Generally speaking, this information is provided by an “environment variable” named PERL5LIB.   On a Unix-like system, this will most-likely be set by a local script (e.g. .bash_profile.   On a Windows system, this will be set in the registry and/or in the System control-panel, or by a profile.

    In any case, perl -V with a capital-V will tell you “what Perl actually knows,” drawing from all of its various sources of information.   “When the rubber finally hits the road,” the list that Perl will obligingly give to you is its authority.

Re: Can't locate JSON.pm in @INC
by Sagacity (Monk) on Feb 13, 2014 at 21:46 UTC

    Hi brewzzer,

    It's been awhile, but I think you can do this: use '/path/to/your/JSON';

    I don't remember if you need single quotes or not! You might have to name the JSON module by it's full name(JSON.pm), or whatever it's extension is, as well. It's a sign of getting old and bad sectors in personal memory.

    Sagacity

    "Of course I was working, can't you see the logged updates at exactly 65 minute intervals!"
Re: Can't locate JSON.pm in @INC
by dwm042 (Priest) on Feb 14, 2014 at 19:12 UTC

    The most likely thing to happen is that there is more than one Perl on your machine. If so, then you installed JSON in one Perl instance and were in fact using another.

    This can happen when the system Perl isn't the commonly used Perl. System packages install in the system Perl.

    The module library directories(locations shown via the array @INC) are separate for separate Perls. When you implemented CPAN for the Perl you are used to using, it then installed a module for the Perl you use.

    Now, I haven't proven this bit of speculation, but it seems pretty logical, given the nature of your issues.

    David

Re: Can't locate JSON.pm in @INC
by jethro (Monsignor) on Feb 13, 2014 at 22:37 UTC

    EDIT: Nevermind

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1074885]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2025-07-10 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.