Why does my Perl program complain "Can't locate URI.pm in @INC"?

22,791

Solution 1

  • Possibly you do not have URI installed. It might not be saved anywhere on your machine, or it might be "installed" in a location.

    • If it's just not installed, then you need to install it from CPAN.
    • If you have it saved to your machine, you just need to let the system know where to get it.

If you have to install it from CPAN, you likely need administrator privileges to put it in the listed directories. But CPAN will allow you to install it to a user directory, so you can still install it.

So if you can't install the module in the directories listed in @INC, then there are the various ways.

  1. Perl 5 reads a environment variable called PERL5LIB. Any directory in that "array" will be prepended to @INC. So anything in the directory structure of $ENV{PERL5LIB} will be preferred to any system directory. (see here)

  2. Another way you can do this is per script. The use lib pragma also inserts specified directories into @INC. (see lib)

    use lib '/path/to/URI/module';
    use URI;
    
  3. The final way, you can do it per run. You can run perl with the -I switch on the command line perl -I/path/to/URI/module -e 1 (see perlrun)

Solution 2

The nonstandard paths in @INC (e.g. /usr/local/packages, perl_remote etc) indicate to me that this is a custom perl installed for a specific purpose probably with reduced functionality to prevent mischief.

Ask the sysadmin.

Solution 3

The array @INC contains the list of places to look for Perl scripts to be evaluated. Your script will not run because it is not in the @INC list. Either:

  1. Put the script in one of the @INC locations; or
  2. Add the location of the file to the $PATH environmental variable; or
  3. Specify the full path of the script when you are calling it.
Share:
22,791
Zacky112
Author by

Zacky112

Updated on November 06, 2020

Comments

  • Zacky112
    Zacky112 over 3 years

    I'm new to Perl. I get the following error when I run a script:

    Can't locate URI.pm in @INC (@INC contains: /usr/local/packages/perl_remote/5.6.1/lib/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/5.6.1 /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1 /usr/local/packages/perl_remote/5.6.1/lib/site_perl .) at (eval 2) line 3.
    Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/HTTP/Request.pm line 3.
    Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/UserAgent.pm line 10.
    BEGIN failed--compilation aborted at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/UserAgent.pm line 10.
    Compilation failed in require at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/Simple.pm line 26.
    BEGIN failed--compilation aborted at /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/LWP/Simple.pm line 26.
    Compilation failed in require at txotf_0_install.pl line 35.
    BEGIN failed--compilation aborted at txotf_0_install.pl line 35.

    What could be the possible reasons of this and how do I get the script to work. Any help will be appreciated.

  • ccheneson
    ccheneson about 14 years
    The problem can also be that the URI.pm module is not installed (liburi-perl package on my ubuntu, but i dont know the module's name on solaris)
  • brian d foy
    brian d foy about 14 years
    Well, not installed or installed in a directory not in @INC.