我正在尝试安装Perl模块的conda软件包。到目前为止,我已经可以使用conda-build
创建包。为此,我有一个包含build.sh
和meta.yaml
文件的食谱。
然后我在新环境中使用conda-install
安装它,我希望能够运行刚安装的Perl模块中的一些Perl脚本。
所有这些步骤都可以正常工作,但是当我运行某些脚本时,我会出错:
Can't locate PMP/util.pm in @INC (you may need to install the PMP::util module) (@INC contains: /.autofs/home/antoine/anaconda2/envs/testCustomChannel/lib/site_perl/5.26.2/x86_64-linux-thread-multi /.autofs/home/antoine/anaconda2/envs/testCustomChannel/lib/site_perl/5.26.2 /.autofs/home/antoine/anaconda2/envs/testCustomChannel/lib/5.26.2/x86_64-linux-thread-multi /.autofs/home/antoine/anaconda2/envs/testCustomChannel/lib/5.26.2 .)
如您所见,执行Perl时似乎无法识别我的Perl模块的某些模块。我知道,要解决此问题,我可以修改@INC变量,并将bin /添加到PATH,并将lib /添加到PERL5LIB,但是我需要在模块安装期间自动执行此过程。
我真的不知道应该在哪里修改环境变量。例如,在创建包期间通过在build.sh
中添加一些内容?还是应该在安装过程中进行管理?如果可以,该怎么办?
任何建议将不胜感激
谢谢
编辑:
meta.yaml =>
{% set name = "module_name" %}
{% set version = "0.8.3" %}
package:
name: "{{ name }}"
version: "{{ version }}"
source:
git_url: ssh://git@adress/bspcore/perl_module.git
build:
number: 0
requirements:
host:
- perl
- perl-extutils-makemaker
run:
- perl
about:
home: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
license: xxx
license_family: xxx
summary: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Build.sh =>
#!/bin/bash
if [ -f Build.PL ]; then
perl Build.PL
perl ./Build
# Make sure this goes in site
perl ./Build install --installdirs site
elif [ -f Makefile.PL ]; then
# Make sure this goes in site
perl Makefile.PL INSTALLDIRS=site
make
make install
else
echo 'Unable to find Build.PL or Makefile.PL. You need to modify build.sh.'
exit 1
fi
chmod u+rwx $PREFIX/bin/*
echo "${PREFIX}"
编辑2:
另一种可以帮助你们更好地了解我的情况的编辑。我刚刚意识到,在构建软件包时,我拥有PMP::util
的perl模块的lib文件夹位于lib/site_perl/5.26.0/Perl_Module
下。我非常确定,如果我能够直接将其安装在lib/
文件夹下,它将解决此问题。但是我不确定如何修改build.sh文件来修改我们构建perl模块的位置。
答案 0 :(得分:2)
这是一个简单的示例,说明如何创建一个conda软件包来安装Perl模块(取决于CPAN模块),该软件包可能会帮助您解决问题:
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ bash Miniconda3-latest-Linux-x86_64.sh
# NOTE: I answered "yes" on the question:
# "Do you wish the installer to initialize Miniconda3 ?" in the
# previous command. This will modify ~/.bashrc
$ source ~/.bashrc # activates base environment
# Next command: Do not automatically activate conda for every terminal window,
# instead run "conda activate" from a given terminal window to
# activate locally. The following command also creates ~/.condarc
$ conda config --set auto_activate_base False
perl-hello / meta.yaml :
package:
name: perl-hello3
version: "1.0"
source:
path: ../src # NOTE: if you had put "src" in same folder as "meta.yaml",
# conda-build would have include the src folder in info/recipe in
# the generated package. It is not necessary to include the
# source code in the generated package.
requirements:
build:
- perl >= 5.22
- make
run:
- perl >= 5.22
about:
license: Artistic
summary: Simple perl function
../ src / :
$ tree ../src
../src
├── lib
│ └── My
│ └── Module.pm
└── Makefile.PL
../ src / Makefile.PL :
use utf8;
use ExtUtils::MakeMaker;
WriteMakefile(
MIN_PERL_VERSION => 5.022000,
NAME => 'My::Module',
VERSION_FROM => 'lib/My/Module.pm',
PREREQ_PM =>
{
'ExtUtils::MakeMaker' => '7.12',
'Data::Dump' => 0,
},
ABSTRACT_FROM => 'lib/My/Module.pm',
AUTHOR => 'Håkon Hægland <hakon.hagland@gmail.com>',
LICENSE => 'perl',
);
../ src / lib / My / Module.pm :
package My::Module;
our $VERSION = 0.01;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT = qw(hello);
our @EXPORT_OK = @EXPORT;
use Data::Dump;
sub hello {
print "Hello world!\n";
my $str = "Testing Perl module Data::Dump";
dd $str;
}
1;
build.sh :
# PERL_MM_USE_DEFAULT=1 -> automatically answer "yes" on config questions
PERL_MM_USE_DEFAULT=1 cpan App::cpanminus
perl ${PREFIX}/bin/cpanm Data::Dump
perl Makefile.PL INSTALLDIRS=site
make
make install
请注意,我使用cpanm
运行了perl ${PREFIX}/bin/cpanm
。我无法简单地以cpanm
的身份运行它,有关更多信息,请参见Can you rely on the shebang of an installed command during build?。
$ conda-build .
(记下生成的输出,并确定生成的包的路径。在我的情况下,路径名称为:
/home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
安装客户端
$ conda install anaconda-client
登录到您的帐户:
$ anaconda login
上传生成的包:
$ anaconda upload /home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
创建一个新环境:
$ conda create --name perltest
$ conda activate perltest
在新环境中安装软件包:
$ conda install -c hakonhagland perl-hello3
# Alternatively: You can test the package locally before uploading with
# "conda install --use-local perl-hello3"
测试程序包:
$ perl -E 'use My::Module; hello'
Hello world!
"Testing Perl module Data::Dump"