如何为动态链接库编写conda配方?

2024-09-28 05:27:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我首先编写了一个bash脚本来创建conda环境,并安装xerus库及其所有依赖项

然后,我尝试从这个脚本创建一个conda包。 虽然它在我的机器上工作(即使在上传到anaconda.org之后),但它对我的同事不起作用。 但是bash脚本确实如此

我假设我在meta.yamlbuild.sh的规范中犯了一个简单的错误。 你能告诉我哪里出错了吗

安装脚本

#!/bin/bash
ENVNAME="${1}"
set -e

if [ -z "${ENVNAME}" ];
then
    echo "Usage: bash install.sh <env_name>"
    exit 0
fi

read -p "Create new conda environment '${ENVNAME}' (y/n)? " answer
case ${answer:0:1} in
    y|Y )
    ;;
    * )
        exit
    ;;
esac

conda create -n ${ENVNAME} -c conda-forge 'python=3.8' python_abi gxx_linux-64 make 'pip>=18.1' numpy openblas suitesparse lapack liblapacke boost-cpp libgomp scipy matplotlib rich
eval "$(conda shell.bash hook)"
conda activate ${ENVNAME}
NUMPY=${CONDA_PREFIX}/lib/python3.8/site-packages/numpy
CXX=${CONDA_PREFIX}/bin/x86_64-conda-linux-gnu-c++

git clone --recurse-submodules https://github.com/libxerus/xerus.git --branch SALSA
cd xerus

cat <<EOF >config.mk
CXX = ${CXX}
COMPATIBILITY = -std=c++17
COMPILE_THREADS = 8
HIGH_OPTIMIZATION = TRUE
OTHER += -fopenmp

PYTHON3_CONFIG = \`python3-config --cflags --ldflags\`

LOGGING += -D XERUS_LOG_INFO
LOGGING += -D XERUS_LOGFILE
LOGGING += -D XERUS_LOG_ABSOLUTE_TIME
XERUS_NO_FANCY_CALLSTACK = TRUE

BLAS_LIBRARIES = -lopenblas -lgfortran
LAPACK_LIBRARIES = -llapacke -llapack
SUITESPARSE = -lcholmod -lspqr
BOOST_LIBS = -lboost_filesystem

OTHER += -I${CONDA_PREFIX}/include -I${NUMPY}/core/include/
OTHER += -L${CONDA_PREFIX}/lib
EOF

ln -s ${CONDA_PREFIX}/include/ ${CONDA_PREFIX}/include/suitesparse
make python
python -m pip install . --no-deps -vv

cd ..
rm -rf xerus

conda生成文件

meta.yaml

{% set name = "Xerus" %}
{% set version = "4.0.1" %}
{% set branch = "SALSA" %}

package:
  name: {{ name|lower + '_' + branch|lower }}
  version: {{ version }}

source:
  - git_url: https://github.com/libxerus/xerus.git
    git_tag: {{ branch }}
    folder: xerus

build:
  number: 1
  skip: true       # [py<34 or win]
  run_exports:
    - python_abi
    - numpy
    - openblas
    - suitesparse
    - lapack
    - liblapacke
    - boost-cpp
    - libgomp

requirements:
  build:
    - {{ compiler('cxx') }}
    - make
    - python {{ python }}
    - pip >=18.1
  host:
    - python_abi
    - numpy
    - openblas
    - suitesparse
    - lapack
    - liblapacke
    - boost-cpp
    - libgomp
  run:
    - python_abi
    - numpy
    - openblas
    - suitesparse
    - lapack
    - liblapacke
    - boost-cpp
    - libgomp

test:
  files:
    - VERSION

about:
  home: https://libxerus.org
  license: "AGPL 3.0"
  license_file: LICENSE
  summary: "A c++ library for numerical calculations with higher order tensors"
  description: |
    The Xerus library is a general purpose library for numerical calculations with higher order tensors, Tensor-Train Decompositions / Matrix Product States and other Tensor Networks.
    The focus of development was the simple usability and adaptibility to any setting that requires higher order tensors or decompositions thereof.
  doc_url: https://libxerus.org/doxygen
  dev_url: https://github.com/libxerus/xerus

build.sh

#!/bin/bash
set -x -e

cd xerus

cat <<EOF >config.mk
CXX = ${CXX}
COMPATIBILITY = -std=c++17
COMPILE_THREADS = 8
HIGH_OPTIMIZATION = TRUE
OTHER += -fopenmp

PYTHON3_CONFIG = \`python3-config --cflags --ldflags\`

LOGGING += -D XERUS_LOG_INFO
LOGGING += -D XERUS_LOGFILE
LOGGING += -D XERUS_LOG_ABSOLUTE_TIME
XERUS_NO_FANCY_CALLSTACK = TRUE

BLAS_LIBRARIES = -lopenblas -lgfortran
LAPACK_LIBRARIES = -llapacke -llapack
SUITESPARSE = -lcholmod -lspqr
BOOST_LIBS = -lboost_filesystem

OTHER += -I${PREFIX}/include -I${PREFIX}/lib/python${PY_VER}/site-packages/numpy/core/include/
OTHER += -L${PREFIX}/lib
EOF

ln -s ${PREFIX}/include/ ${PREFIX}/include/suitesparse
make python
${PYTHON} -m pip install . --no-deps -vv

test.sh

#!/bin/bash
set -e

VERSION=$(cat VERSION)

export PYTHONPATH=''

${PYTHON} <<EOF
print("="*80)
print("\trun_test.sh for Xerus ${VERSION}")
print("="*80)
import xerus
assert xerus.__version__ == '${VERSION}', xerus.__version__+" != ${VERSION}"
EOF

Tags: numpybashprefixincludeversionloggingshconda

热门问题