What's a good way to get python 3.7+ (with pip) onto a non-python project?

I’ve got a an android project and I need to have python 3.7+ and pip on the command line. Xenial seems to be providing 3.4 (documentation says 3.5 but that’s not what I see), Focal 3.6, Bionic 3.2 (again, documentation says 3.6). Also, despite what the documentation says, the build works only when I don’t specify dist: trusty.

How do I go about installing python 3.7+ and pip?

What I tried:

  • addons:
      apt:
        sources:
          - deadsnakes
        packages:
          - python3.7
    

    This doesn’t come with pip

  • same, but with with packages like this:

        packages:
        - python3.7-dev
        - python3-pip
    

    This fails due to incompatibility between the two packages

  •     packages:
        - python3.7-venv
    
    before_script:
      - python3.7 -m venv ~/venv
      - source ~/venv/bin/activate
    

    This fails due to the following:

    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

    Including libssl-dev or python3-openssl doesn’t help. A similar error breaks the following:

    before_script:
      - curl https://bootstrap.pypa.io/get-pip.py | sudo python3.7 -
    
  •     packages:
        - python3.7-venv
    
    before_script:
      - python3.7 -m ensurepip --upgrade
    

    This fails due to:

    No module named ensurepip

  • before_script:
      - pyenv install --skip-existing 3.6.0 && pyenv global 3.6.0
    

    this works, but the highest stable version is somehow 3.6, and also this slows down the build considerably

  • Use dist: focal which comes with 3.8.2; or
  • install the necessary version with pyenv and cache the result
Imprint