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

后端 未结 5 1220
臣服心动
臣服心动 2021-01-03 07:47

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         


        
相关标签:
5条回答
  • 2021-01-03 08:21

    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.
    0 讨论(0)
  • 2021-01-03 08:22

    In my case I just copied the perl folder to another machine and added path to bin folder to PATH environment variable. In order to fix the issue, I had to run the proper installation of ActivePerl which at the end setup all the environment properly for perl.

    0 讨论(0)
  • 2021-01-03 08:25
    • 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)

    0 讨论(0)
  • 2021-01-03 08:27

    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.

    0 讨论(0)
  • 2021-01-03 08:42

    This is not to say that any of the other answers aren't all good advice (they very likely address your issue), but I ran into a similar issue which had me puzzled for a couple hours. While I'm not sure this addresses the OP's problem, perhaps someone stumbling across this in the future will save themselves some time troubleshooting...

    I found on a new CentOS server that despite @INC reporting the path to my custom libraries included and despite all file and directory permissions being set correctly mod_perl was still bailing out with a message that it "Can't locate" the modules in question. This was doubly puzzling because similar scripts with the same "use lib" statement that Apache's PerlRequire was using were able to run without issue.

    The culprit turned out to be SELinux, and disabling it took care of this immediately. More details on the /var/log/messages info that led me to this as well as other general gripes can be found here.

    0 讨论(0)
提交回复
热议问题