Travis 构建失败,没有名为 scipy 的模块(使用 Miniconda)

Travis build failing, no module named scipy (using Miniconda)

我有一个依赖 scipy 的包。我已经知道通过 apt-get 安装 scipy 会给我们一个过时的包版本,并且通过 pip 安装它会使 Travis VM 超时,所以我决定在期间下载并安装 Miniconda我的测试,就像许多其他问题中所建议的那样。

但是,每当我推送到 GitHub 并且 Travis 运行我的单元测试时,它都找不到 scipy 包。错误消息只是 ImportError: No module named 'scipy'.

这是我的 .travis.yml 文件的内容。 python --version 正确指向 "to Python 3.4.4 :: Continuum Analytics, Inc." 和 conda list 表明安装了 scipy 0.17.0。如果有人感兴趣,这里是 full log of my Travis build.

language: python
python:
  # We don't actually use the Travis Python, but this keeps it organized.
  - "3.4"
install:
  - sudo apt-get update
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
  - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
      wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
    else
      wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
    fi
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
  - hash -r
  - conda config --set always_yes yes --set changeps1 no
  - conda update -q conda
  # Useful for debugging any issues with conda
  - conda info -a
  - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy scikit-learn matplotlib
  - source activate test-environment
  - conda list
  - python --version
  - whereis python
  - python setup.py install
script: nosetests

您的python与travis日志中看到的虚拟环境不对应。猜测一下,我会说 nosetests 正在使用它自己的 venv。

所以看看 nosetests:它可能有一个不同的、硬编码的 shebang 作为第一行(head -n1 $(which nosetests) 可能有),因此使用不同的 python 和不同的 venv。

如果以上正确,解决方法可能是安装您自己的 nosetests 版本。那应该优先考虑(在您的 PATH 中更早)。