问题

软件 >> Perl
Questions in category: Perl (Perl).

安装Perl后如何添加模块?

Posted by haifeng on 2021-10-25 10:01:21 last update 2024-09-12 16:53:26 | Answers (1) | 收藏


比如现在需要在 Perl 中使用 ImageMagick, 在 .pl 文件中通常要写

use Image::Magick;

也就是启用 Image::Magick 模块. 如果 Perl 是默认安装的, 则不会预先安装此模块. 在执行 .pl 文件时, 会提示下面的信息

 

Can't locate Image/Magick.pm in @INC (you may need to install the Image::Magick module) (@INC contains: C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.


如果安装的是 strawberry Perl, 则已经安装了 cpanm. 在 Windows 下可以通过 where cpanm 查看其是否能直接调用.

然后通过 

cpanm Module::Name

直接安装需要的模块. 模块可以在 CPAN 网上查找.

例如: 在命令符窗口下键入 cpanm Image::Magick  就可以安装 Image::Magick 模块.

 

cpanm Image::Magick
--> Working on Image::Magick
Fetching http://www.cpan.org/authors/id/J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz ... OK
Configuring Image-Magick-7.0.11-3 ... OK
Building and testing Image-Magick-v7.0.11 ... FAIL
! Installing Image::Magick failed. See C:\Users\haife\.cpanm\work\1635127678.42820\build.log for details. Retry with --force to force install it.

 

 


键入 perl -MCPAN -e shell 可进入 CPAN 的 shell 模式

 

perl -MCPAN -e shell
Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environment variables didn't work. at C:\Strawberry\perl\vendor\lib/Term/ReadLine/readline.pm line 410.

cpan shell -- CPAN exploration and modules installation (v2.28)
Enter 'h' for help.

cpan>