6

Within my project, I (have to) use a feature included in Numpy 1.8, but not in earlier versions (the formatteroption of numpy.set_printoptions).

Since Travis CI build machines are based on Ubuntu 12.04, by default I only have Numpy 1.6.1 available. I then tried to install the Numpy-1.8.1-Debian-package for Ubuntu 14.04 and it's dependencies manually, which led to further problems:

I need to install the packages libblas3 and liblapack3 to be able to install Numpy 1.8, which is not possible when liblapack3gf and libblas3gf are installed on the system (which are there by default), since the packages would "break" them. If I apt-get remove them, automatically libatlas3gf-base is being installed via the same apt-get-command (which is not the case on a standard Ubuntu system, I even set one up on my local machine to make sure). If I then try to uninstall Vlibatlas3gf-baseV, again liblapack3gf and libblas3gf are automatically being installed again.

I do not really know how to handle this problem, or how to get around it to get Numpy 1.8 working with Travis. I also tried the suggestions for upgrading Numpy via pip provided here, but within Travis this did not work.

Any help is highly appreciated!

Thank you very much!


The solution:

I completed rth's answer to the following .travis.yml-file, with further help from here and here:

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

Now everything works as expected. Please note: you will not be able to import and use PyLab with this setup, see the comments below for the explanations.

Community
  • 1
  • 1
mindm49907
  • 278
  • 2
  • 10
  • You probably need to install PyQt4 to import pylab (see this [answer](https://stackoverflow.com/questions/19231944/anaconda-unable-to-import-pylab) ), `sudo apt-get install python-qt4` . As a side note, the use of `pylab` should be avoided when possible, especially in a non interactive environment, and explicit imports are to be preferred: `import numpy as np`, `import matplotlib.pyplot as plt` (if you need plots) etc. – rth Jun 03 '15 at 08:23
  • @rth Why should it be avoided? Because if it's reasonable to avoid it, I would tend to rather put the effort in changing my code than to further try to get PyLab working in Travis. – mindm49907 Jun 03 '15 at 08:37
  • Well if you do `from pylab import *` lots of stuff get imported in the namespace, from `numpy`, `scipy`, `matplotlib` etc and you are not really in control of what's happening. Especially if you do unit tests, it is much better import the required modules explicitly. This is not really related to your problem though, it's just that your default matplotlib backend seem to require PyQt4 (whether you use pylab or not), you can also change the backend to say `Agg` to avoid the problem. – rth Jun 03 '15 at 09:35
  • 1
    @rth Thank you for the explanations! I replaced the import of ``pylab`` by an import of ``numpy``, since I realized that I did not use things from other packages than ``numpy``anyway this was in either way the better option! I'll update my question and mark this one as solved! – mindm49907 Jun 03 '15 at 15:10
  • Please note that conda has an [example `.travis.yml`](http://conda.pydata.org/docs/travis.html) file that includes a few tricks and cosmetic changes. – Midnighter May 04 '16 at 21:40

3 Answers3

3

Building scientific python modules from sources (whether compiling directly or with pip) in a continuous integration work-flow is slow (15 min for numpy, another 15 min if you need scipy, etc), and a waste of resources.

You should rather use a binary distribution of numpy, such as the one provided by Anaconda. For Travis CI you could use,

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

Also have a look at this more complete setup example for Travis CI.

rth
  • 10,680
  • 7
  • 53
  • 77
2

I tried installing Numpy 1.8.2 with pip on Travis CI and it seems to have worked.

Here is the content of my .travis.yml file:

language: python

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

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

You can see that it is successfully printing 1.8.2 in this build log.

Hope this helps!

Dominic Jodoin
  • 2,538
  • 18
  • 21
  • 1
    Thank you for your answer, but as others pointed out building takes time, so I would like to test the other possibilities first, but might come back to your solution I these won't work for me. – mindm49907 Jun 03 '15 at 08:18
2

UPDATE: Travis CI is no longer free of charge for public GitHub repositories. GitHub Actions is an alternative that is free of charge for public repositories.


numpy is now 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, so there is no need to build numpy on Travis CI.

Excerpt from an 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
0 _
  • 10,524
  • 11
  • 77
  • 109