23

Possible Duplicate:
What's the easiest way to install a missing Perl module?

I'm attempting to run a Perl script to convert SCXML to Graphviz DOT. I modified the first line of the script to:

#!/usr/bin/env perl

and chmod +x the file. When I run it via ./scmxl2dot.pl I see the following error output:

Can't locate LWP/Simple.pm in @INC (@INC contains: /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/site_perl/5.12.3 /opt/local/lib/perl5/vendor_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/vendor_perl/5.12.3 /opt/local/lib/perl5/5.12.3/darwin-multi-2level /opt/local/lib/perl5/5.12.3 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendor_perl .) at ./scmxml2dot.pl line 14.
BEGIN failed--compilation aborted at ./scmxml2dot.pl line 14.

Line 14 of the file is use LWP::Simple;

How do I:

  1. Find out if I have this thing (module?) installed, and/or
  2. Get LWP::Simple and make it available to the script?

This is running under OS X 10.7.3 and Perl 5.12.3 (as seen in the error).

Community
  • 1
  • 1
Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • 2
    From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim May 09 '12 at 22:24

3 Answers3

39
  1. You're already determined that you don't have it (somewhere it can be found).

  2. perl -MCPAN -e'install "LWP::Simple"'

ikegami
  • 367,544
  • 15
  • 269
  • 518
6
  1. Execute the following from the command line:

    perl -MLWP::Simple -e 1
    

    If you don't get any output from the above command then the module is installed; if you get an error, it's not installed

  2. to install use

    perl -MCPAN -e'install "LWP::Simple"'
    

When perl encounters use My::Module it goes over the elements of the built-in @INC module that contains directory names. In each directory it check if there is a subdirectory called "My" and if in that subdirectory there is a file called "Module.pm".

check where LWP::Simple module is installed on your system and type below line just above the use LWP::Simple statement of your code.

    use lib '/usr/local/module';
    use LWP::Simple;
Sunil Kartikey
  • 525
  • 2
  • 11
3

Take a look at the Perldoc webpage. This will tell you which modules are standard Perl modules and which ones aren't.

You can also use the perldoc command to find out if a Perl module is installed, and if it is, its documentation.

$ perldoc LWP::Simple

(If Perldoc doesn't execute as a command do ls -l /usr/bin/perl*. On Macs, some of the Perl commands don't have the execute bit turned on. To turn it on, do sudo chmod a+x /usr/bin/perl).

It just happens the LWP::Simple isn't a standard Perl module, and if you don't have it, you'll have to install it. Most people have already told you about cpan. Unfortunately, by default, the Mac doesn't have the needed command line development tools installed. You'll have to install them.

Once they're installed, you can use the cpan command to install LWP::Simple:

$ sudo cpan   #Run cpan and configure it. It takes about 3 minutes
cpan> install LWP::Simple
cpan> exit
David W.
  • 105,218
  • 39
  • 216
  • 337
  • `sudo cpan` is a very bad idea in general. It lets you install into system directories, which can overwrite system modules. This can cause problems later on, e.g. because you changed files that belong to a system package or because you inadvertently upgraded a module that is used by a system program to an incompatible newer version. Better: Use [local::lib](https://metacpan.org/pod/local::lib) to install modules in your home directory, or build your own perl (easiest way: [perlbrew](https://perlbrew.pl/)) that lives entirely in your home directory. – melpomene Sep 13 '18 at 20:00