首页 > 解决方案 > 如何在没有 conda 的情况下从源代码安装 Bob

问题描述

Bob建议其用户使用安装其软件包conda,但我不想使用conda. 如何从源代码安装它?

标签: pythonpython-bob

解决方案


解释

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

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

例如,bob.extension 的 conda 配方在这里

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, click-plugins, nose, coverage, sphinx, sphinx_rtd_theme, 和bob.buildoutpip。(您还可以查看requirements.txttest-requirements.txtBob 包的依赖项的 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 从源代码安装。

如果您喜欢 Python 工作环境,则可以使用pip全局或在您的私有上 安装包。virtualenv您将需要手动安装所需的所有包(直接或间接),因为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是您机器上的最大并行进程数。


推荐阅读