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

Hi,
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:
https://travis-ci.com/github/willprobert/travis_test_python_c_gsl

the yaml file is the following:

language: generic
dist: xenial
env: PYTHON_VERSION=3.6.2
python: 3.6
before_install: 
  - sudo apt-get update
  - sudo apt-get install libgsl-dev
install:
  - pip install --user -r tests/requirements.txt
script:
  - 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?

Was


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.

install:
  - pip install --user -r tests/requirements.txt
script:
  - 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 …

script:
  - 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.