Search code examples
pythonscipytravis-ciminiconda

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


I have a package which has scipy as a dependency. I am already aware that installing scipy through apt-get gives us an outdated version of the package and that installing it through pip times out the Travis VM, so I decided to download and install Miniconda during my tests, like suggested in many other questions.

However, whenever I push to GitHub and Travis runs my unit tests, it fails to find the scipy package. The error message is simply ImportError: No module named 'scipy'.

Here is the content of my .travis.yml file. python --version points correctly "to Python 3.4.4 :: Continuum Analytics, Inc." and conda list shows that scipy 0.17.0 is installed. If anyone is interested, here is the 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

Solution

  • Your python doesn't correspond to the virtual environment seen in the travis log. At a guess, I'd say nosetests is using its own venv.

    So look at nosetests: it may have a different, hardcoded shebang as first line (head -n1 $(which nosetests) may do), thus using a different python and different venv.

    If the above is correct, the solution is probably to install your own version of nosetests. That should take priority (being earlier in your PATH).