在 Travis CI 中安装 Numpy 1.8

Install Numpy 1.8 in Travis CI

在我的项目中,我(必须)使用 Numpy 1.8 中包含的功能,但早期版本中没有(numpy.set_printoptionsformatter 选项)。

由于 Travis CI 构建机器基于 Ubuntu 12.04,默认情况下我只有 Numpy 1.6.1 可用。然后我尝试为 Ubuntu 14.04 安装 Numpy-1.8.1-Debian-package 及其依赖项,这导致了进一步的问题:

我需要安装包 libblas3liblapack3 才能安装 Numpy 1.8,当 liblapack3gflibblas3gf 安装在系统(默认情况下存在),因为软件包会 "break" 它们。如果我 apt-get remove 它们, 自动 libatlas3gf-base 正在通过相同的 apt-get-命令安装(标准 [=54 不是这种情况) =] 系统,我什至在我的本地机器上设置了一个以确保)。如果我随后尝试卸载 Vlibatlas3gf-baseV,liblapack3gflibblas3gf 将再次自动安装。

我真的不知道如何处理这个问题,或者如何绕过它让 Numpy 1.8 与 Travis 一起工作。我还尝试了通过 pip 提供的 here 升级 Numpy 的建议,但在 Travis 中这不起作用。

非常感谢任何帮助!

非常感谢!


解决方法:

here and here 的进一步帮助下,我完成了 rth 对以下 .travis.yml 文件的回答:

language: python

matrix:
  include:
    - python: 2.7
      env: NUMPY=1.8 SCIPY=0.13

notifications:
  email: false

before_install:
 - travis_retry wget http://repo.continuum.io/miniconda/Miniconda-3.8.3-Linux-x86_64.sh -O miniconda.sh
 - chmod +x miniconda.sh
 - bash miniconda.sh -b -p $HOME/miniconda
 - export PATH=/home/travis/miniconda/bin:$PATH
 - conda update --yes conda

install:
 - conda create --yes -n test python=$TRAVIS_PYTHON_VERSION
 - source activate test
 - conda install --yes numpy=$NUMPY scipy=$SCIPY matplotlib pip
 - pip install setuptools
 - [ ... some other packages to install ... ]
 - python setup.py install

script:
 - nosetests

现在一切正常。请注意:您将不能通过此设置导入和使用 PyLab,请参阅下面的评论以了解解释。

我尝试在 Travis CI 上使用 pip 安装 Numpy 1.8.2,它似乎有效。

这是我的 .travis.yml 文件的内容:

language: python

before_script:
  - pip uninstall numpy -y
  - pip install -I numpy==1.8.2

script: python -c 'import numpy; print numpy.version.version'

在这个build log.

可以看到打印成功了1.8.2

希望对您有所帮助!

在持续集成工作流程中,从源代码(无论是直接编译还是使用 pip 编译)构建科学 python 模块很慢(numpy 需要 15 分钟,如果需要则需要另外 15 分钟 scipy, 等), 浪费资源。

您应该使用 numpy 的二进制发行版,例如 Anaconda 提供的发行版。对于 Travis CI 你可以使用,

language: python

before_script:
  - wget http://repo.continuum.io/miniconda/Miniconda-3.8.3-Linux-x86_64.sh -O miniconda.sh
  - chmod +x miniconda.sh
  - export PATH=/home/travis/miniconda/bin:$PATH
  - conda install --yes numpy=1.8

另请查看 Travis CI 的更完整 setup example

更新Travis CI is no longer free of charge for public GitHub repositories. GitHub Actions 是 public 个存储库免费的替代方案。


numpy 现在是 pre-installed on Travis CI. For the rare occasion that the pre-installed version is older than the latest numpy release, binary releases of numpy are available from PyPI,因此无需在 Travis CI.

上构建 numpy

摘自example .travis.yml file

addons:
  apt:
    packages:
    - gfortran
    - libatlas-dev
    - libatlas-base-dev
    - liblapack-dev
    - libgmp-dev
    - libmpfr-dev

before_install:
  - pip install -U --only-binary=numpy,scipy numpy scipy