Specifying python version (python 3) in language:generic under xenial image

I’m hoping to use the language: generic under the xenial image to test a project that uses both C and Python. The Python tests call the C code. I have tested both the C code and Python code independently on Travis-CI and each works fine.

The build is here:

the yaml file is the following:

language: generic
dist: xenial
python: 3.6
  - sudo apt-get update
  - sudo apt-get install libgsl-dev
  - pip install --user -r tests/requirements.txt
  - python -m pytest

The difficulty I seem to be having is that my tests require a specific Python version (which seems possible with the generic image) yet I can’t seem load Python 3.

How do I load a specific Python version (Python 3) so that pip and pytest will work with that version of Python?

Any help would be much appreciated!

You should use language: python if you need a specific version of Python, or manage a Python run time yourself if you insist on language: generic.

My understanding of the documentation is that I must use generic to have access to both GCC and Python - there’s no other way. Is that correct?

Which document(s) did you look at?


one of them?

Thanks for the help. Yes, that page, and the page on “Minimal and Generic images”. The documentation on Xenial Build specifically mentions that “Python 3.6.7 will be used when no language version is explicitly set.” However, if I use language: generic and don’t mention a version of Python, then when I used pip or python in the install and script parts of the yaml file then the build log clearly shows Python 2.7 is being used.

  - pip install --user -r tests/requirements.txt
  - python -m pytest

You need to invoke python3 instead.

Thanks for the help. I’ve tried this. As I mentioned I’ve tried setting the default Python 3 version but pip does not work for python3 - it fails for python 3 (even though the documentation says python3 is default).

The following fails …

  - pip install --user -r tests/requirements.txt
  - python3 -m pytest

How do I invoke python3 while also invoking pip3? Or have pip install modules for Python3?

I’m still not able to install Python3 modules in this environment in Travis. Any help on this topic would be much appreciated.