在安装conda软件包期间更新@INC变量 [英] Updating the @INC variable during installation of a conda package
问题描述
我正在尝试安装Perl模块的conda软件包.到目前为止,我已经能够使用 conda-build
创建软件包.为此,我有一个食谱,其中包含一个 build.sh
和一个 meta.yaml
文件.
I am trying to install a conda package of a Perl module. So far I'm able to create the package using conda-build
. For that I have a recipe containing a build.sh
and a meta.yaml
files.
然后我在新环境中使用 conda-install
安装它,我希望能够运行刚安装的Perl模块中的一些Perl脚本.
I then install it using conda-install
in a new environment, I'd like to be able able to run some Perl scripts located in the Perl module I just installed.
所有这些步骤都可以正常工作,但是当我运行某些脚本时,我会出错:
All those steps work well but when I'm running some scripts I have an error saying :
在@INC中找不到PMP/util.pm(您可能需要安装PMP :: util模块)(@ INC包含:/.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,但是我需要在模块安装期间自动执行此过程.
As you can see it seems that some module of my Perl module are not recognized when I execute Perl. I know that to fix this issue I can modify the @INC variable and add the bin/ to the PATH and the lib/ to the PERL5LIB but I need to automatize this process during the installation of the module.
我真的不知道应该在哪里修改环境变量.在创建包的过程中,例如在 build.sh
中添加一些内容?还是应该在安装过程中进行管理?如果可以,该怎么办?
I don't really know where I should modify the environment variable. During the creation of the package by adding something in the build.sh
for example ? Or should I manage that during the installation and if so, how could I do that ?
任何建议将不胜感激,
谢谢
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}"
另一种可以帮助你们更好地了解我的情况的编辑.我只是意识到,在构建软件包时,我拥有 PMP :: util
的perl模块的lib文件夹位于 lib/site_perl/5.26.0/Perl_Module
下.我非常确定,如果能够直接将其安装在 lib/
文件夹下,它将解决此问题.但是我不确定如何修改build.sh文件来修改我们构建perl模块的位置.
Another edit that could help you guys understand better my situation. I just realized that when I build the package the lib folder of my perl module in which I have PMP::util
lives under lib/site_perl/5.26.0/Perl_Module
. I'm pretty sure that if I'm able to install it directly under the lib/
folder it will resolve this issue. However I'm not sure how to modify the build.sh file to modify the place where we build the perl module.
推荐答案
下面是一个简单的示例,说明如何创建一个conda软件包来安装Perl模块(取决于CPAN模块),该软件包可能会帮助您解决问题:
Here is a simple example of how to create a conda package that installs a Perl module (which depends on a CPAN module) that might help you solve your issue:
$ 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
请注意,我使用 perl $ {PREFIX}/bin/cpanm
运行了 cpanm
.我无法简单地将其作为 cpanm
运行,请参见可以您是在构建过程中依靠已安装命令的shebang吗?以获得更多信息.
Note that I ran cpanm
using perl ${PREFIX}/bin/cpanm
. I was not able to simply run it as cpanm
, see Can you rely on the shebang of an installed command during build? for more information.
$ conda-build .
(记下生成的输出,并确定生成的包的路径.在我的情况下,路径名称为:
(Take a note of the generated output, and determine the path of the generated package. In my case the path name was:
/home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
将程序包上传到anaconda服务器
-
安装客户端
$ conda install anaconda-client
-
登录到您的帐户:
Login to your account:
$ anaconda login
-
上传生成的包:
Upload the generated package:
$ anaconda upload /home/hakon/miniconda3/conda-bld/linux-64/perl-hello3-1.0-pl526_0.tar.bz2
-
创建新环境:
Create a new enviroment:
$ conda create --name perltest
$ conda activate perltest
在新环境中安装软件包:
Install the package in the new environment:
$ conda install -c hakonhagland perl-hello3
# Alternatively: You can test the package locally before uploading with
# "conda install --use-local perl-hello3"
测试程序包:
Test the package:
$ perl -E 'use My::Module; hello'
Hello world!
"Testing Perl module Data::Dump"
这篇关于在安装conda软件包期间更新@INC变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!