简体   繁体   English

CPAN模块声称已安装但未安装

[英]CPAN modules claim to install but dont

Running UBUNTU 14.04 through VirtualBox. 通过VirtualBox运行UBUNTU 14.04。

When executing a script, i get the following error: 执行脚本时,出现以下错误:

Can't locate XML/Simple.pm in @INC (@INC contains:...

Now, when I check the directories in @INC , they indeed do not contain XML/Simple.pm 现在,当我检查@INC的目录时,它们确实不包含XML/Simple.pm

I then tried installing it through cpan 然后我尝试通过cpan安装它

sudo cpan XML::Simple

and it tells me that: 它告诉我:

XML::Simple is up to date (2.20).

which, according to perl is not true, since the output of 根据perl是不正确的,因为输出

perl -e "use XML::Simple "

is

Can't locate XML/Simple.pm in @INC (@INC contains:

So, what am I missing? 那么,我想念什么?

An alternative way to install Perl modules on Linux systems is from the distribution repository. 在Linux系统上安装Perl模块的另一种方法是从分发存储库中获得。 On Debian/Ubuntu systems the general rules for converting a CPAN distribution name to an apt package name is: 在Debian / Ubuntu系统上,将CPAN发行名称转换为apt软件包名称的一般规则是:

  1. convert the module name to lower case 将模块名称转换为小写
  2. convert '::' to '-' 转换成 '-'
  3. add a 'lib' prefix and a '-perl' suffix 添加“ lib”前缀和“ -perl”后缀

So the package name for XML::Simple would be: libxml-simple-perl and you could install it with: 因此,XML :: Simple的软件包名称为: libxml-simple-perl ,您可以使用以下命令进行安装:

sudo apt-get install libxml-simple-perl

There are exceptions to these rules, but you can always search by Perl module name: 这些规则有例外,但是您始终可以按Perl模块名称进行搜索:

apt-cache search XML::Simple

You won't get the absolute latest version of the module from your distro's package repository but for stable (some might say 'moribund') modules like XML::Simple that usually doesn't matter. 您不会从发行版的软件包存储库中获得模块的绝对最新版本,但是对于稳定的(有些人可能会说“ moribund”)模块(如XML :: Simple)通常并不重要。

If you do have multiple versions of Perl installed, then installing from your distro's package repository will usually only make the package available for the system Perl in /usr/bin 如果确实安装了多个版本的Perl,则从发行版的软件包存储库进行安装通常只会使软件包可用于/usr/bin的系统Perl。

In general, you should not mess with the system perl . 通常,您不应惹恼系统perl

Use 采用

$ which perl

and

$ sudo which perl

to see where each perl lives. 看看每个perl住哪里。

As a System Administrator or Application developer there is a common problem that you usally face. 作为系统管理员或应用程序开发人员,通常会遇到一个常见问题。 When you develope an Application you probably always want the newest and latest modules, and not the modules that are shiped with the distribution. 开发应用程序时,您可能总是需要最新的模块,而不是发行版附带的模块。 But even if you are fine with the versions in your Linux distibution sometimes you have the problem that you want a specific Perl module and it is not included in your distribution. 但是,即使您对Linux发行版本中的版本感到满意,有时您仍然会遇到需要特定的Perl模块的问题,并且该模块未包含在您的发行版中。

The usally way to solve that problem was just a call to lets say cpan XML::Simple and the latest module gets downloaded and installed. 解决该问题的常用方法只是调用cpan XML::Simple然后下载并安装了最新模块。

But when you do this, you are messing with the package system of your Linux distribution. 但是,当您这样做时,就会弄乱了Linux发行版的软件包系统。 Lets say you already had XML::Simple installed from your package system. 假设您已经从软件包系统中安装了XML :: Simple。 Your cpan command will now update the already installed version and replace it with a newer version. 您的cpan命令现在将更新已经安装的版本,并用较新的版本替换它。 All of that is fine, until your Linux distribution for example would ship an update for libxml-simple-perl . 所有这些都很好,例如在您的Linux发行版将发布libxml-simple-perl的更新之前。 What than could happen is that your new version gets reverted to an old version. 可能发生的是,您的新版本恢复为旧版本。

And because all Perl modules usally depends on other Perl Modules, an install command also can update a lot of other Perl modules. 而且由于所有Perl模块通常都依赖于其他Perl模块,因此install命令还可以更新许多其他Perl模块。

All of that behaviour can leads to weired bugs. 所有这些行为都可能导致奇怪的错误。 Either way in application you write, or also in application shiped in your distribution. 无论是在编写的应用程序中,还是在分发中附带的应用程序中,都可以。

To "resolve" that problem, usally the best way is to leave the system Perl completly alone. 要“解决”该问题,通常最好的方法是完全不使用Perl系统。 Compile your own Perl Version completly from source. 从源代码完全编译自己的Perl版本。 That Perl version than has its own perl libraries that you can install directly from CPAN without messing with the System Perl. 该Perl版本具有自己的perl库,您可以直接从CPAN安装该库,而不会弄乱System Perl。

Now to do that very easy, their exists a tool named Perlbrew 现在,要做到这一点非常容易,他们就有了一个名为Perlbrew的工具

With this tool you can easily install any Perl Version. 使用此工具,您可以轻松安装任何Perl版本。 For example just typing perlbrew install perl-5.16.0 and it completly installs Perl 5.16.0 in your home directory! 例如,仅输入perlbrew install perl-5.16.0即可在您的主目录中完全安装Perl 5.16.0! It also setups all paths so a call to perl in your system resolve to this perlbrew installation. 它还会设置所有路径,以便在系统中对perl的调用可以解决此perlbrew安装问题。

Also an important part is that this Perl installation is just in your home directory under a normal user account. 同样重要的是,此Perl安装仅在普通用户帐户下的主目录中。 You don't need sudo or a root Account, because Perl gets installed in your home directory. 您不需要sudo或root帐户,因为Perl已安装在您的主目录中。

The same goes for Perl Modules. Perl模块也是如此。 If you want to install a Perl Module in your Perlbrew installation you just type cpan XML::Simple (or cpanm XML::Simple checkout App::cpanminus ). 如果要在Perlbrew安装中安装Perl模块,则只需键入cpan XML::Simple (或cpanm XML::Simple checkout App::cpanminus )。

Now the important part. 现在重要的部分。 On your system you already had a setup for Perlbrew. 在您的系统上,您已经安装了Perlbrew。 When you executed your installation program that Perlbrew installation was used. 当您执行安装程序时,即使用了Perlbrew安装。 But in this Perlbrew installation there was no XML::Simple installed. 但是在此Perlbrew安装中,没有安装XML :: Simple。

You then executed sudo cpan XML::Simple to install XML::Simple. 然后,您执行sudo cpan XML::Simple以安装XML :: Simple。 The problem is that all sudo commands just gets executed as a root user. 问题在于,所有sudo命令只是以root用户身份执行。 That means your system Perl /usr/bin/perl is used instead of your Perlbrew installation in /home/qiime/perl5/perlbrew/perls/perl-5.16.0/bin/perl 这意味着您将使用系统Perl /usr/bin/perl ,而不是在/home/qiime/perl5/perlbrew/perls/perl/perl-5.16.0/bin/perl中安装/home/qiime/perl5/perlbrew/perls/perl-5.16.0/bin/perl

You successfully install XML::Simple in your System Perl. 您已成功在System Perl中安装XML :: Simple。 But your Perlbrew installation didn't had XML::Simple installed and thus it still returned an error that it could not found XMl::Simple. 但是您的Perlbrew安装没有安装XML :: Simple,因此仍然返回错误,找不到XMl :: Simple。

The only thing you really needed to do was just cpan XML::Simple installing XML::Simple in your perlbrew installation in your home directory. 您真正唯一需要做的就是在主目录中的perlbrew安装中使用cpan XML::Simple安装XML :: Simple。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM