【问题标题】:Can't locate custom module in @INC在@INC 中找不到自定义模块
【发布时间】:2018-09-19 20:44:10
【问题描述】:

我有一个从模块运行代码的基本 Perl 脚本。切换到新计算机后,我不再能够运行此脚本。目录树是这样设置的:

SatanicBot
  src
    SatanicBot
      Bot.pm
      Utils.pm
  run.pl <-- The script that uses the module

run.pl 中的 use 语句如下:

use warnings;
use strict;
use diagnostics;

use Bot::BasicBot;

use Cwd qw(abs_path);
use FindBin;
use lib abs_path("$FindBin::Bin/SatanicBot");
# Without this, I get an error that is essentially caused by it not being to find the module.
use SatanicBot::Bot; 

当我运行 run.pl 时,我收到以下错误:

Can't locate SatanicBot/Bot.pm in @INC (you may need to install the SatanicBot::Bot module) (@INC contains: /Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/darwin-2level /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0 /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/darwin-2level /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0 .) at src/run.pl line 12.

如您所见,它声明@INC 包含 SaticBot::Bot 模块所在的目录,但它找不到它。我真的被难住了。

【问题讨论】:

  • 什么是$FindBin::Bin/SatanicBot?可能和$FindBin::Bin/src/SatanicBot不一样
  • 这应该链接到正确的位置,因为 run.pl 已经在 src 目录中。第二个暗示 Bot.pm 位于 satanicBot/src/src/SatanicBot 中。至少它看起来会这样做。
  • 提示:lib 是包含模块的目录的常规名称,而不是 src。 (bin 用于脚本)

标签: perl perl-module


【解决方案1】:

@INC 包含:

/Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot

但要在文件/Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot/Bot.pm 中找到SatanicBot::Bot 包,您希望@INC 包含

/Users/elifoster/Desktop/Dev/SatanicBot/src

【讨论】:

  • 尝试在原始机器上执行“find / -name Bot.pm -print”以获取位置,然后查看将该文件、安装程序或相关文件组复制到您的路径中。
  • 这行得通,但我想知道为什么。模块文件不在/src,在/src/SatanicBot,为什么偏爱/src?
  • 要查找Foo::Bar::Baz,perl 在@INC 中搜索名为Foo/Bar/Baz.pm 的文件,而不是名为Baz.pm 的文件
  • 哦,有道理。谢谢!
猜你喜欢
  • 1970-01-01
  • 2019-10-08
  • 2016-01-06
  • 2013-05-19
  • 2019-05-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
相关资源
最近更新 更多