以下是如何创建安装 Perl 模块(依赖于 CPAN 模块)的 conda 包的简单示例,可能会帮助您解决问题:
在 Linux 上安装 miniconda
$ 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 <hako[email protected] /cdn-cgi/l/email-protection>',
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
using perl ${PREFIX}/bin/cpanm
。我无法简单地运行它cpanm
, see 您可以在构建过程中依赖已安装命令的 shebang 吗? https://github.com/conda/conda-build/issues/3592了解更多信息。
构建包
$ conda-build .
(记下生成的输出,并确定生成的包的路径。在我的例子中,路径名称为:
/home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
将包上传到anaconda服务器
注册一个新用户蟒蛇云 https://anaconda.org/account/register
-
安装客户端
$ conda install anaconda-client
-
登录到您的帐户:
$ anaconda login
-
上传生成的包:
$ anaconda upload /home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
测试包(可以在任何 Linux 机器上完成):
-
创建新环境:
$ 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"