scipy ImportError on travis-ci
I found two ways around this difficulty:
As @unutbu suggested, build your own virtual environment and install everything using pip inside that environment. I got the build to pass, but installing scipy from source this way is very slow.
Following the approach used by the pandas project in this .travis.yml file and the shell scripts that it calls, force travis to use system-wide site-packages, and install numpy and scipy using apt-get. This is much faster. The key lines are
virtualenv: system_site_packages: true
in travis.yml before the
before_install
group, followed by these shell commandsSITE_PKG_DIR=$VIRTUAL_ENV/lib/python$TRAVIS_PYTHON_VERSION/site-packagesrm -f $VIRTUAL_ENV/lib/python$TRAVIS_PYTHON_VERSION/no-global-site-packages.txt
and then finally
apt-get install python-numpyapt-get install python-scipy
which will be found when nosetests tries to import them.
Update
I now prefer a conda-based build, which is faster than either of the strategies above. Here is one example on a project I maintain.
This is covered in the official conda documentation: Using conda with Travis CI.
The
.travis.yml
fileThe following shows how to modify the
.travis.yml
file to use Miniconda for a project that supports Python 2.6, 2.7, 3.3, and 3.4.NOTE: Please see the Travis CI website for information about the basic configuration for Travis.
language: pythonpython: # We don't actually use the Travis Python, but this keeps it organized. - "2.6" - "2.7" - "3.3" - "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 # Replace dep1 dep2 ... with your dependencies - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ... - source activate test-environment - python setup.py installscript: # Your test script goes here
I found this approach to work:
http://danielnouri.org/notes/2012/11/23/use-apt-get-to-install-python-dependencies-for-travis-ci/
Add these lines to your Travis configuration to use a
virtualenv
with--system-site-packages
:
virtualenv: system_site_packages: true
You can thus install Python packages via
apt-get
in thebefore_install
section, and use them in your virtualenv:
before_install: - sudo apt-get install -qq python-numpy python-scipy
A real-world use of this approach can be found in nolearn.