Installing both Python and R for a Travis build?

Here is a travis.yml I use for my pyrle package. It just installs R usinq the ubuntu package manager:

language: python
python:
  - "3.6"
install:
  - pip install cython pytest hypothesis
  - sudo apt-get install -y r-base
  - echo 'source("https://bioconductor.org/biocLite.R"); biocLite("S4Vectors"); biocLite("GenomicRanges")' > install.R
  - python setup.py install

script:
  - py.test tests/

Another way is to install R through conda. Here is an example from the pyranges package:

# Stolen from http://conda.pydata.org/docs/travis.html
language: python
python:
  # We don't actually use the Travis Python, but this keeps it organized.
  - "3.6"
install:
  - sudo apt-get update
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
  - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
  - 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
  - conda config --add channels bioconda
  - conda config --add channels r
  # Useful for debugging any issues with conda
  - conda info -a
  - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy pandas pytest pytest-cov cython tabulate hypothesis bedtools # ray
  - source activate test-environment
  - python setup.py install # will install ncls
  - python --version
  - python -c 'import pandas as pd; print(pd.__version__)'
  - ls tests

script: py.test -v tests # verbose to see that tests run and so that travis does not time out on hypothesis tests

Your question title and question body are quite different.

Regarding the python+R Question

Similarly to The Unfun Cat's answer which uses travis to install python and installs R with apt, you can use travis for R and install python with apt:

language: r
install:
  - sudo apt-get install -y python2.7 python3.6

Note that travis also has an apt addon which makes your .yaml a bit cleaner (but arguably less portable).

language: r
addons:
  apt:
    packages:
    - python2.7
    - python3.6

The different python versions installed should be accessible to Sys.which as python2.7 and python3.6 instead of just "python". which python will return either the last version installed or else the last installed python2*.


Regarding the networking question

There are a number of reasons a you may be unable to establish a connection. A common reason is that the port is already in use. Port 6011 is sometimes used by the X window system (ref), so it is possible a one of travis's services is using it.

Using this reference on how to check for used ports you might try adding something like

sudo lsof -i -P -n | grep LISTEN | grep 6011

to your travis.yaml so you can see in the log if the port is used. You might also try a different unused port number in your script.

I did find this github comment referencing similar issues with R specifically; perhaps you can find more there.