github workflow python use system packages

Hi all,

I am trying to setup an action to automatically test a python module.

The module needs two python packages that are not present on pip and needs to be installed via apt-get

What I’ve tried is the following

runs-on: ubuntu-16.04
      max-parallel: 4
        python-version: [2.7, 3.5, 3.6, 3.7]

    - uses: actions/checkout@v1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
        python-version: ${{ matrix.python-version }}
    - name: Install system dependencies
      run: |
        sudo apt-get update \
        && sudo apt-get install -y \
          python-dbus python-gobject \
          python3-dbus python3-gi \
        && sudo rm -rf /var/lib/apt/lists/*
    - name: Install python dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Test with nose
      run: |
        pip install nose coverage
        nosetests --with-coverage --cover-package=mypkg tests

But when I run it I got from nose the error

import dbus

no module name dbus

So that mean that python can’t find the python-dbus installed packages.

How to solve this?




As apparent from the setup-python action description, it does not use the system Python distribution.

As such, you probably have to make it aware of the system-wide library path that Debian/Ubuntu uses.

That would be something along the lines of

PYTHONPATH="/usr/lib/python${{ matrix.python-version }}/dist-packages:${PYTHONPATH}" nosetests --with-coverage --cover-package=mypkg tests

Please note that this would not help if the interpreter is run with the argument -E (that ignores any relevant environment data).

Please also note that your script specifies 3 different Python 3.x versions. There is no straightforward method in which one can assure that any specific version of any “python3-%s” Debian/Ubuntu .deb package will install in all /usr/lib/python3.x/dist-packages folders.

According to the Debian Python policy, using

PYTHONPATH="/usr/lib/python${{ matrix.python-version }}/dist-packages:/usr/lib/python3/dist-packages:${PYTHONPATH}" ......

will get you covered for all Python3 versions for which the corresponding package installed a module.

But it may wreak havoc with 2.x if the 2.x module is not found for some reason.


Unfortunately, I have a similar problem (python3-xapian package) and wasn’t able to solve the issue with the PYTHONPATH trick :frowning: