簡體   English   中英

無法從CPAN安裝Perl模塊

[英]Can't install a Perl module from CPAN

嘗試在Linux上運行Perl腳本時,出現錯誤:“找不到Devel / GlobalDestruction.pm”

因此,我運行了CPAN shell並嘗試安裝它:

$ perl -MCPAN -e shell
cpan> install Devel::GlobalDestruction

但是,不幸的是,出現了一個錯誤:

...
Looks good
Warning: prerequisite Devel::GlobalDestruction::XS 0 not found.
Warning: prerequisite Sub::Exporter::Progressive 0.001011 not found.
Only one of PREFIX or INSTALL_BASE can be given.  Not both.
No 'Makefile' created  HAARG/Devel-GlobalDestruction-0.13.tar.gz
  /usr/bin/perl Makefile.PL PREFIX=/home/onlinetv/perl/usr -- NOT OK
Failed during this command:
 HAARG/Devel-GlobalDestruction-0.13.tar.gz    : writemakefile NO -- No 'Makefile' created

可能這里有問題:“只能給出PREFIX或INSTALL_BASE之一。不能同時給出。”

但是我不知道如何解決它。

更新

>o conf輸出以下內容:

make_arg           [PREFIX=/home/onlinetv/perl/usr]
make_install_arg   []
make_install_make_command undef
makepl_arg         [PREFIX=/home/onlinetv/perl/usr]
mbuild_install_build_command [./Build]
mbuildpl_arg       [PREFIX=/home/onlinetv/perl/usr]

我只打印了與PREFIX相關的行

-bash-3.2$ set | grep ^PERL
PERL5LIB=/home/onlinetv/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=/home/onlinetv/perl5
PERL_MB_OPT='--install_base "/home/onlinetv/perl5"'
PERL_MM_OPT=INSTALL_BASE=/home/onlinetv/perl5

cpan配置為向Makefile.PL提供一個設置,而Makefile.PL正在從環境中選擇一個沖突的設置。

看起來您使用的是local :: lib,它使用INSTALL_BASE范例。 這樣,只需告訴cpan停止指定PREFIX cpan shell中,

o conf makepl_arg ''
o conf mbuildpl_arg ''
o conf commit

同時,修復make_arg的廢話值。

o conf make_arg ''
o conf commit

當您有很多時間並考慮StackOverflow時,cpan是一個很好的工具。 請安裝App :: cpanminus並改用cpanm。

curl -L https://cpanmin.us | perl - --sudo App::cpanminus

要解決此錯誤:

嘗試在Linux上運行Perl腳本時,出現錯誤:“找不到Devel / GlobalDestruction.pm”

cpanm

我使用宮川達彥的cpanm

按照該文檔中的個人安裝指南,下一部分將把cpanm安裝到〜/ bin中 ,該文件必須位於PATH中

cd ~/bin
curl -L https://cpanmin.us/ -o cpanm
chmod +x cpanm
which cpanm

現在,使用cpanm將缺少的庫安裝在包含原始腳本的給定目錄內名為local的 目錄中

cd <dir>
cpanm -L local Devel::GlobalDestruction

要包括安裝在該目錄中的軟件包,

  • 使用FindBin查找當前本地目錄,然后

  • 使用lib查找您最近安裝的文件。

這是要添加到原始腳本中的代碼,位於dir中

use FindBin qw( $Bin );
use lib “$Bin/local/lib/perl5”;

cpanm代碼以遞歸方式安裝所有依賴項。 在我的課程中,我得到了兩個:

cpanm -L local Devel::GlobalDestruction
--> Working on Devel::GlobalDestruction
Fetching http://www.cpan.org/authors/id/H/HA/HAARG/Devel-GlobalDestruction-0.13.tar.gz ... OK
Configuring Devel-GlobalDestruction-0.13 ... OK
==> Found dependencies: Sub::Exporter::Progressive
--> Working on Sub::Exporter::Progressive
Fetching http://www.cpan.org/authors/id/F/FR/FREW/Sub-Exporter-Progressive-0.001011.tar.gz ... OK
Configuring Sub-Exporter-Progressive-0.001011 ... OK
Building and testing Sub-Exporter-Progressive-0.001011 ... OK
Successfully installed Sub-Exporter-Progressive-0.001011
Building and testing Devel-GlobalDestruction-0.13 ... OK
Successfully installed Devel-GlobalDestruction-0.13
2 distributions installed 

作為上述的一個小變化

cpanm參數從大寫L [-L]更改為小寫L [-l],以查看它們在完成是否有所不同,或者在程序包依賴項集中是否有所不同。

在兩次嘗試之間刪除本地目錄,以確保安裝的軟件包最少。


一個測試

作為上述示例的使用,這是對03_minusc.t測試用例的修改,該測試用例在我將上述庫下載到的本地目錄中的目錄中找到了新庫:

與原始測試的鏈接:

http://cpansearch.perl.org/src/HAARG/Devel-GlobalDestruction-0.13/t/03_minusc.t

這是對代碼的修改:

use FindBin qw( $Bin );
use lib "$Bin/local/lib/perl5";
use Devel::GlobalDestruction;

這是輸出:

1..3
ok - Test properly running under minus-c
ok - BEGIN is not GD with -c
./test.pl syntax OK
ok - Final cleanup object destruction properly in GD

閱讀Sinan的帖子后,我認為下面使用的我的perl / opt / local / bin / perl應該更改為他建議的/ home / onlinetv / perl / bin / perl

這是經過修改的測試代碼:

#!/opt/local/bin/perl

BEGIN {
  if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
    unshift @INC, sub {
      die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm';
    };
  }
}

{
  package Test::Scope::Guard;
  sub new { my ($class, $code) = @_; bless [$code], $class; }
  sub DESTROY { my $self = shift; $self->[0]->() }
}

sub ok ($$) {
  print "not " if !$_[0];
  print "ok";
  print " - $_[1]" if defined $_[1];
  print "\n";
  !!$_[0]
}

BEGIN {
  require B;
  B::minus_c();

  print "1..3\n";
  ok( $^C, "Test properly running under minus-c" );
}

use FindBin qw( $Bin );
use lib "$Bin/local/lib/perl5";
use Devel::GlobalDestruction;

BEGIN {
    ok !in_global_destruction(), "BEGIN is not GD with -c";
}

our $foo;
BEGIN {
  $foo = Test::Scope::Guard->new( sub {
    ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) or do {
      require POSIX;
      POSIX::_exit(1);
    };
  });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM