【问题标题】:How to install Bob from source without conda如何在没有 conda 的情况下从源代码安装 Bob
【发布时间】:2018-06-12 18:40:05
【问题描述】:

Bob 使用conda 向其用户推荐install 其软件包, 但我不想使用conda。如何从源代码安装它?

【问题讨论】:

    标签: python python-bob


    【解决方案1】:

    说明

    首先,使用 conda 安装 Bob 要容易得多,并且是安装 Bob 的受支持方式。请再次考虑使用 conda 安装 Bob,然后再继续。 Bob 是用 C++ 和 Python 混合编写的,并链接到许多不同的 C/C++ 库,而 Conda 是一个与语言无关的二进制包管理器,可以处理所有这些。

    如果要从源代码安装 Bob,首先需要手动安装其依赖项。每个包的依赖项都列在每个 Bob 包的 conda 配方中。从其 conda 配方中,您必须安装(如果存在)requirements:buildrequirements:hostrequirements:runtest:requires。这些包是 conda 包而不是 pip 包;其中一些可能是 pip 包(名称可能不同),其中一些可能只是一个 C/C++ 库,您应该使用系统的包管理器(或从源代码)安装它。

    例如,bob.extension 的 conda 配方是 here

    requirements:
      host:
        - python {{ python }}
        - setuptools {{ setuptools }}
      run:
        - python
        - setuptools
        - click
        - click-plugins
    
    test:
      requires:
        - bob-devel {{ bob_devel }}.*
        - nose
        - coverage
        - sphinx
        - sphinx_rtd_theme
        - boost
        - cmake
        - pkg-config
        - freetype
        - libblitz
        - numpy
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - bob.buildout
    

    解析这个配方意味着你需要安装: boost, cmake, pkg-config, freetype, libblitz, C and C++ compilers, 可能还有 numpy 使用系统的包管理器,然后安装 click, nose, @987654, coveragesphinxsphinx_rtd_themebob.buildout 与 pip。 (您还可以查看 Bob 包的 requirements.txttest-requirements.txt 以获取依赖项的 pip 包名称,但可能不会更新以匹配其 conda 配方)。 bob-devel 是一个 conda 元包,不使用 conda 时无需安装。

    这将使您的环境准备好编译(如果需要)、安装和测试bob.extension。搭建好环境后,可以使用pip安装bob.extension

    pip install bob.extension
    

    然后,您需要按照 Bob 包依赖项的顺序安装下一个 Bob 包。正如您所看到的,这可能非常耗时,但这是唯一可行的方法,因为 Bob 的包已经开发并且它们的依赖关系发生了变化。

    说明

    这些说明将帮助您安装大多数包含 C++ 代码的 Bob 包,这些代码很难安装。安装完这些包后,您很可能可以使用 pip 安装其余的 Bob 包。

    依赖关系

    您需要先使用系统的包管理器安装 Bob 包依赖项。

    +-------------+------+-------------------------+---------------------+
    | Library     | Min. | License                 | Notes               |
    |             | Vers |                         |                     |
    |             | io   |                         |                     |
    |             | n    |                         |                     |
    +=============+======+=========================+=====================+
    | Std. C/C++  | any  | Depends on the compiler | Required by all     |
    | Libraries   |      |                         | packages with C/C++ |
    |             |      |                         | bindings            |
    +-------------+------+-------------------------+---------------------+
    | `Blitz++ <h | 0.10 | `Artistic-2.0 <http://w | Required by all     |
    | ttp://www.o |      | ww.opensource.org/licen | packages with C/C++ |
    | onumerics.o |      | ses/Artistic-2.0>`__    | bindings            |
    | rg/blitz>`_ |      | or LGPLv3+ or GPLv3+    |                     |
    | _           |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `Lapack <ht | any  | BSD-style               | Required by         |
    | tp://www.ne |      |                         | ``bob.math``        |
    | tlib.org/la |      |                         |                     |
    | pack>`__    |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `Python <ht | 2.5  | `Python-2.0 <http://www | Required by all     |
    | tp://www.py |      | .opensource.org/license | packages            |
    | thon.org>`_ |      | s/Python-2.0>`__        |                     |
    | _           |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `Boost <htt | 1.34 | `BSL-1.0 <http://www.op | Required by all     |
    | p://www.boo |      | ensource.org/licenses/B | packages with C/C++ |
    | st.org>`__  |      | SL-1.0>`__              | bindings            |
    +-------------+------+-------------------------+---------------------+
    | `HDF5 <http | 1.8. | `HDF5                   | Required by all I/O |
    | ://www.hdfg | 4    | License <ftp://ftp.hdfg | operations (direct  |
    | roup.org/HD |      | roup.org/HDF5/current/s | or indirect         |
    | F5>`__      |      | rc/unpacked/COPYING>`__ | dependencies to     |
    |             |      | (BSD-like, 5 clauses)   | ``bob.io.base``)    |
    +-------------+------+-------------------------+---------------------+
    | `libpng <ht | 1.2. | `libpng                 | Required by all     |
    | tp://libpng | 42   | license <http://www.lib | packages that do    |
    | .org/pub/pn | ?    | png.org/pub/png/src/lib | image I/O and       |
    | g/libpng.ht |      | png-LICENSE.txt>`__     | manipulation        |
    | ml>`__      |      |                         | (depend directly or |
    |             |      |                         | indirectly on       |
    |             |      |                         | ``bob.io.image``)   |
    +-------------+------+-------------------------+---------------------+
    | `libtiff <h | 3.9. | BSD-style               | Required by all     |
    | ttp://www.r | 2    |                         | packages that do    |
    | emotesensin |      |                         | image I/O and       |
    | g.org/libti |      |                         | manipulation        |
    | ff/>`__     |      |                         | (depend directly or |
    |             |      |                         | indirectly on       |
    |             |      |                         | ``bob.io.image``)   |
    +-------------+------+-------------------------+---------------------+
    | `giflib <ht | 4.1. | `MIT <http://www.openso | Required by all     |
    | tp://giflib | 6-9  | urce.org/licenses/MIT>` | packages that do    |
    | .sourceforg |      | __                      | image I/O and       |
    | e.net/>`__  |      |                         | manipulation        |
    |             |      |                         | (depend directly or |
    |             |      |                         | indirectly on       |
    |             |      |                         | ``bob.io.image``)   |
    +-------------+------+-------------------------+---------------------+
    | `libjpeg <h | 6.2? | `GPL-2.0 <http://www.op | Required by all     |
    | ttp://libjp |      | ensource.org/licenses/G | packages that do    |
    | eg.sourcefo |      | PL-2.0>`__              | image I/O and       |
    | rge.net/>`_ |      | or later (also          | manipulation        |
    | _           |      | commercial)             | (depend directly or |
    |             |      |                         | indirectly on       |
    |             |      |                         | ``bob.io.image``)   |
    +-------------+------+-------------------------+---------------------+
    | `FFMpeg <ht | 0.5  | `LGPL-2.1 <http://www.o | Required by all     |
    | tp://ffmpeg | (ffm | pensource.org/licenses/ | packages that do    |
    | .org>`__    | pe   | LGPL-2.1>`__            | video I/O and       |
    | or          | g)   | or later, or            | manipulation        |
    | `libAV <htt | or   | `GPL-2.0 <http://www.op | (depend directly or |
    | p://libav.o | 0.8  | ensource.org/licenses/G | indirectly on       |
    | rg>`__      | (lib | PL-2.0>`__              | ``bob.io.video``)   |
    |             | av   | or later                |                     |
    |             | )    |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `MatIO <htt | 1.3. | `BSD-2-Clause <http://w | Required by all     |
    | p://matio.s | 3?   | ww.opensource.org/licen | packages that do    |
    | ourceforge. |      | ses/BSD-2-Clause>`__    | Matlab I/O and      |
    | net>`__     |      |                         | manipulation        |
    |             |      |                         | (depend directly or |
    |             |      |                         | indirectly on       |
    |             |      |                         | ``bob.io.matlab``)  |
    +-------------+------+-------------------------+---------------------+
    | `VLFeat <ht | 0.9. | `BSD-2-Clause <http://w | Required by         |
    | tp://www.vl | 14   | ww.opensource.org/licen | ``bob.ip.base`` and |
    | feat.org/>` |      | ses/BSD-2-Clause>`__    | all dependents      |
    | __          |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `LIBSVM <ht | 2.89 | `BSD-3-Clause <http://w | Required by         |
    | tp://www.cs | +    | ww.opensource.org/licen | ``bob.learn.libsvm` |
    | ie.ntu.edu. |      | ses/BSD-3-Clause>`__    | `                   |
    | tw/~cjlin/l |      |                         | and all dependents  |
    | ibsvm/>`__  |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    | `CMake <htt | 2.8  | `BSD-3-Clause <http://w | Required by all     |
    | p://www.cma |      | ww.opensource.org/licen | packages with C/C++ |
    | ke.org>`__  |      | ses/BSD-3-Clause>`__    | bindings. **Use at  |
    |             |      |                         | least CMake 2.8.12  |
    |             |      |                         | on Mac OS X**.      |
    +-------------+------+-------------------------+---------------------+
    | `pkg-config | any  | `GPL-2.0 <http://www.op | Required to find    |
    |  <http://ww |      | ensource.org/licenses/G | dependencies while  |
    | w.freedeskt |      | PL-2.0>`__              | building bob        |
    | op.org/wiki |      |                         | packages.           |
    | /Software/p |      |                         |                     |
    | kg-config/> |      |                         |                     |
    | `__         |      |                         |                     |
    +-------------+------+-------------------------+---------------------+
    

    安装依赖后,您可以使用 pip 从源代码安装。

    可以使用pip 全局或在您的私人上安装软件包 virtualenv,如果这是您喜欢 Python 工作环境的方式。你 将需要手动安装您需要的所有软件包(直接或间接), 因为pip/setuptools 目前无法连贯地安装 Python 用于构建的包,例如许多 包。

    例如,在新创建的虚拟机中安装bob.io.image 环境,这里是要执行的命令序列:

    $ pip install numpy
    $ pip install bob.extension
    $ pip install bob.blitz
    $ pip install bob.core
    $ pip install bob.io.base
    $ pip install bob.io.image
    

    每个pip 命令必须单独执行,尊重包间 依赖。

    以下内容将不会按预期工作:

    $ #Do not do this:
    $ pip install numpy bob.io.image
    

    核心包的依赖可以概括为7层 以下脚本可用于使用pip 安装所有核心包:

    $ bash pip_install_bob.sh
    -------------------------
    #!/bin/bash
    set -e
    
    get_layer() {
    case $1 in
     1)
       packages=("bob.extension")
       ;;
     2)
       packages=("bob.blitz")
       ;;
     3)
       packages=("bob.core" "bob.ip.draw")
       ;;
     4)
       packages=("bob.io.base" "bob.sp" "bob.math")
       ;;
     5)
       packages=("bob.ap" "bob.measure" "bob.db.base" "bob.io.image" "bob.io.video" "bob.io.matlab" "bob.ip.base" "bob.ip.color" "bob.ip.gabor" "bob.learn.activation" "bob.learn.libsvm" "bob.learn.boosting")
       ;;
     6)
       packages=("bob.io.audio" "bob.learn.linear" "bob.learn.mlp" "bob.db.wine" "bob.db.mnist" "bob.db.atnt" "bob.ip.flandmark" "bob.ip.facedetect" "bob.ip.optflow.hornschunck" "bob.ip.optflow.liu")
       ;;
     7)
       packages=("bob.learn.em" "bob.db.iris")
       ;;
    esac
    }
    
    for layer in `seq 1 7`;
    do
     get_layer ${layer}
     for pkg in "${packages[@]}";
     do
       pip install $pkg
     done
    done
    

    为了加快最后一个脚本中的编译速度,您可以在并行线程中进行编译。只需设置一个环境变量BOB_BUILD_PARALLEL=N,其中N 是您机器上的最大并行进程数。

    【讨论】:

      【解决方案2】:

      由于某种原因,我不能对@183.amir 的帖子发表评论,但这应该被视为对How to install Bob from source without conda 的评论。为了加快 183.amir 最终脚本中的编译速度,您可以在并行线程中进行编译。只需设置一个环境变量BOB_BUILD_PARALLEL=N,其中N 是您机器上的最大并行进程数。

      【讨论】:

      • 谢谢。我也添加了那部分。
      猜你喜欢
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2019-11-04
      • 2012-09-07
      • 1970-01-01
      • 2021-07-05
      • 2021-02-19
      • 1970-01-01
      相关资源
      最近更新 更多